From 4af15aa945832aac08999ca583184187960eb4df Mon Sep 17 00:00:00 2001 From: "ye.yp" <1436237912@qq.com> Date: Sat, 14 Mar 2026 02:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- my_agent_test2.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/my_agent_test2.py b/my_agent_test2.py index ef78613..9869eee 100644 --- a/my_agent_test2.py +++ b/my_agent_test2.py @@ -2,7 +2,7 @@ import os import asyncio -from agentscope.agent import ReActAgent +from agentscope.agent import ReActAgent, UserAgent from agentscope.formatter import OpenAIChatFormatter from agentscope.memory import InMemoryMemory from agentscope.model import OpenAIChatModel @@ -14,7 +14,7 @@ LLAMA_CPP_MODEL_NAME = os.getenv("LLAMA_CPP_MODEL_NAME", "Qwen3.5-35B-A3B-UD-Q8_ LLAMA_CPP_API_KEY = os.getenv("LLAMA_CPP_API_KEY", "EMPTY") -async def creating_react_agent() -> None: +async def main(): """创建一个 ReAct 智能体并运行一个简单任务。""" # 准备工具 toolkit = Toolkit() @@ -32,14 +32,16 @@ async def creating_react_agent() -> None: formatter=OpenAIChatFormatter(), toolkit=toolkit, ) + + user = UserAgent(name="user") + + msg = await user() + while True: + msg = await yyp_bot(msg) + msg = await user(msg) + if msg.get_text_content() == "exit": + break - msg = Msg( - name="user", - content="你好!yyp_bot,用 Python 运行 Hello World。", - role="user", - ) - - await yyp_bot(msg) +asyncio.run(main()) -asyncio.run(creating_react_agent()) \ No newline at end of file