We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
`"""创建Agent实例和Workflow实例""" import Agently agent = ( Agently.create_agent() .set_settings("current_model", "OAIClient") .set_settings("model.OAIClient.url", "https://api.moonshot.cn/v1") .set_settings("model.OAIClient.options", { "model": "moonshot-v1-8k" }) .set_settings("model.OAIClient.auth", { "api_key": "******" }) ) workflow = Agently.Workflow() """创建执行块(Chunk)"""
@workflow.chunk( chunk_id = "Start", type = "Start" )
@workflow.chunk( chunk_id = "User Input", handles = { "outputs": [{ "handle": "user_input" }], } ) def user_input_executor(inputs, storage): return { "user_input": input("[User]: ") }
@workflow.chunk( chunk_id = "Assistant Reply", handles = { "inputs": [{ "handle": "user_input" }], "outputs": [{ "handle": "assistant_reply" }], } ) def assistant_reply_executor(inputs, storage): chat_history = storage.get("chat_history") or [] reply = ( agent .chat_history(chat_history) .input(inputs["user_input"]) .start() ) print("[Assistant]: ", reply) return { "assistant_reply": reply }
@workflow.chunk( chunk_id = "Update Chat History", handles = { "inputs": [ { "handle": "user_input" }, { "handle": "assistant_reply" }, ], }, ) def update_chat_history_executor(inputs, storage): chat_history = storage.get("chat_history") or [] chat_history.append({ "role": "user", "content": inputs["user_input"] }) chat_history.append({ "role": "assistant", "content": inputs["assistant_reply"] }) storage.set("chat_history", chat_history) return
@workflow.chunk( chunk_id = "Goodbye", ) def goodbye_executor(inputs, storage): print("Bye~👋") return
"""连接执行块""" workflow.chunks["Start"].connect_to(workflow.chunks["User Input"]) ( workflow.chunks["User Input"].handle("user_input") .if_condition(lambda data: data == "#exit").connect_to(workflow.chunks["Goodbye"]) .else_condition().connect_to(workflow.chunks["Assistant Reply"].handle("user_input")) ) workflow.chunks["User Input"].handle("user_input").connect_to(workflow.chunks["Update Chat History"].handle("user_input")) workflow.chunks["Assistant Reply"].handle("assistant_reply").connect_to(workflow.chunks["Update Chat History"].handle("assistant_reply")) workflow.chunks["Update Chat History"].connect_to(workflow.chunks["User Input"])
"""获取工作流Mermaid代码(可绘图)""" print(workflow.draw())
"""启动工作流""" workflow.start()`
这是在官网中拿到的关于workflow使用的例子,如果我在这个例子中使用2个agent,第2个agent需要拿到第一个agent的reply,并且由于是多轮对话,那么我需要如何写chat_history
The text was updated successfully, but these errors were encountered:
需要考虑两个问题:
思路上:
Sorry, something went wrong.
对于“将get_first_agent_reply块的agent请求结果通过storage或是inputs传递给get_second_agent_reply块即可”有没有什么例子?
您好,我们在官网已经更新了workflow相关的教程,可以访问agently.tech/guides/workflow查看
No branches or pull requests
`"""创建Agent实例和Workflow实例"""
import Agently
agent = (
Agently.create_agent()
.set_settings("current_model", "OAIClient")
.set_settings("model.OAIClient.url", "https://api.moonshot.cn/v1")
.set_settings("model.OAIClient.options", { "model": "moonshot-v1-8k" })
.set_settings("model.OAIClient.auth", { "api_key": "******" })
)
workflow = Agently.Workflow()
"""创建执行块(Chunk)"""
启动块
@workflow.chunk(
chunk_id = "Start",
type = "Start"
)
用户输入块
@workflow.chunk(
chunk_id = "User Input",
handles = {
"outputs": [{ "handle": "user_input" }],
}
)
def user_input_executor(inputs, storage):
return { "user_input": input("[User]: ") }
Agent回复块
@workflow.chunk(
chunk_id = "Assistant Reply",
handles = {
"inputs": [{ "handle": "user_input" }],
"outputs": [{ "handle": "assistant_reply" }],
}
)
def assistant_reply_executor(inputs, storage):
chat_history = storage.get("chat_history") or []
reply = (
agent
.chat_history(chat_history)
.input(inputs["user_input"])
.start()
)
print("[Assistant]: ", reply)
return { "assistant_reply": reply }
对话记录更新块
@workflow.chunk(
chunk_id = "Update Chat History",
handles = {
"inputs": [
{ "handle": "user_input" },
{ "handle": "assistant_reply" },
],
},
)
def update_chat_history_executor(inputs, storage):
chat_history = storage.get("chat_history") or []
chat_history.append({ "role": "user", "content": inputs["user_input"] })
chat_history.append({ "role": "assistant", "content": inputs["assistant_reply"] })
storage.set("chat_history", chat_history)
return
退出块
@workflow.chunk(
chunk_id = "Goodbye",
)
def goodbye_executor(inputs, storage):
print("Bye~👋")
return
"""连接执行块"""
workflow.chunks["Start"].connect_to(workflow.chunks["User Input"])
(
workflow.chunks["User Input"].handle("user_input")
.if_condition(lambda data: data == "#exit").connect_to(workflow.chunks["Goodbye"])
.else_condition().connect_to(workflow.chunks["Assistant Reply"].handle("user_input"))
)
workflow.chunks["User Input"].handle("user_input").connect_to(workflow.chunks["Update Chat History"].handle("user_input"))
workflow.chunks["Assistant Reply"].handle("assistant_reply").connect_to(workflow.chunks["Update Chat History"].handle("assistant_reply"))
workflow.chunks["Update Chat History"].connect_to(workflow.chunks["User Input"])
"""获取工作流Mermaid代码(可绘图)"""
print(workflow.draw())
"""启动工作流"""
workflow.start()`
这是在官网中拿到的关于workflow使用的例子,如果我在这个例子中使用2个agent,第2个agent需要拿到第一个agent的reply,并且由于是多轮对话,那么我需要如何写chat_history
The text was updated successfully, but these errors were encountered: