Files
my_agent_test2/my_agent_test2.py

45 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import asyncio
from agentscope.agent import ReActAgent
from agentscope.formatter import OpenAIChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.model import OpenAIChatModel
from agentscope.tool import ToolResponse, Toolkit, execute_python_code
from agentscope.message import ImageBlock, Msg, TextBlock, URLSource
LLAMA_CPP_BASE_URL = os.getenv("LLAMA_CPP_BASE_URL", "http://yyplab.site:8033/v1")
LLAMA_CPP_MODEL_NAME = os.getenv("LLAMA_CPP_MODEL_NAME", "Qwen3.5-35B-A3B-UD-Q8_K_XL.gguf")
LLAMA_CPP_API_KEY = os.getenv("LLAMA_CPP_API_KEY", "EMPTY")
async def creating_react_agent() -> None:
"""创建一个 ReAct 智能体并运行一个简单任务。"""
# 准备工具
toolkit = Toolkit()
toolkit.register_tool_function(execute_python_code)
yyp_bot = ReActAgent(
name="yyp_bot",
sys_prompt="你是一个名为 yyp_bot 的助手",
model=OpenAIChatModel(
model_name=LLAMA_CPP_MODEL_NAME,
api_key=LLAMA_CPP_API_KEY,
client_kwargs={"base_url": LLAMA_CPP_BASE_URL}
),
memory=InMemoryMemory(),
formatter=OpenAIChatFormatter(),
toolkit=toolkit,
)
msg = Msg(
name="user",
content="你好yyp_bot用 Python 运行 Hello World。",
role="user",
)
await yyp_bot(msg)
asyncio.run(creating_react_agent())