这个msg是在循环外面的
msg = None while True: msg = await agent(msg) msg = await user(msg) if msg.get_text_content() == "exit": breakagentscope-ai/agentscope: AgentScope: Agent-Oriented Programming for Building LLM Applications
input版本:
from agentscope.agent import ReActAgent from agentscope.model import DashScopeChatModel from agentscope.formatter import DashScopeChatFormatter from agentscope.memory import InMemoryMemory from agentscope.tool import Toolkit, execute_python_code, execute_shell_command import os, asyncio async def main(): toolkit = Toolkit() toolkit.register_tool_function(execute_python_code) toolkit.register_tool_function(execute_shell_command) agent = ReActAgent( name="Friday", sys_prompt="You're a helpful assistant named Friday.", model=DashScopeChatModel( model_name="qwen-max", api_key=os.environ["DASHSCOPE_API_KEY"], stream=True, ), memory=InMemoryMemory(), formatter=DashScopeChatFormatter(), toolkit=toolkit, ) msg = None while True: msg = await agent(msg) print(f"Friday: {msg.get_text_content()}") user_input = input("You: ") if user_input.lower() == "exit": break from agentscope.message import Msg msg = Msg(name="user", content=user_input, role="user") asyncio.run(main())