init
This commit is contained in:
22
conversational_agents/chatbot/README.md
Normal file
22
conversational_agents/chatbot/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# ReAct Agent Example
|
||||
|
||||
This example showcases a **ReAct** agent in AgentScope. Specifically, the ReAct agent will discuss with the user in
|
||||
an alternative manner, i.e., chatbot style. It is equipped with a suite of tools to assist in answering user queries.
|
||||
|
||||
> 💡 Tip: Try ``Ctrl+C`` to interrupt the agent's reply to experience the realtime steering/interruption feature!
|
||||
|
||||
## Quick Start
|
||||
|
||||
Ensure you have installed agentscope and set ``DASHSCOPE_API_KEY`` in your environment variables.
|
||||
|
||||
Run the following commands to set up and run the example:
|
||||
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
|
||||
> Note:
|
||||
> - The example is built with DashScope chat model. If you want to change the model used in this example, don't
|
||||
> forget to change the formatter at the same time! The corresponding relationship between built-in models and
|
||||
> formatters are list in [our tutorial](https://doc.agentscope.io/tutorial/task_prompt.html#id1)
|
||||
> - For local models, ensure the model service (like Ollama) is running before starting the agent.
|
||||
48
conversational_agents/chatbot/main.py
Normal file
48
conversational_agents/chatbot/main.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""The main entry point of the ReAct agent example."""
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from agentscope.agent import ReActAgent, UserAgent
|
||||
from agentscope.formatter import DashScopeChatFormatter
|
||||
from agentscope.memory import InMemoryMemory
|
||||
from agentscope.model import DashScopeChatModel
|
||||
from agentscope.tool import (
|
||||
Toolkit,
|
||||
execute_python_code,
|
||||
execute_shell_command,
|
||||
view_text_file,
|
||||
)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
"""The main entry point for the ReAct agent example."""
|
||||
toolkit = Toolkit()
|
||||
toolkit.register_tool_function(execute_shell_command)
|
||||
toolkit.register_tool_function(execute_python_code)
|
||||
toolkit.register_tool_function(view_text_file)
|
||||
|
||||
agent = ReActAgent(
|
||||
name="Friday",
|
||||
sys_prompt="You are a helpful assistant named Friday.",
|
||||
model=DashScopeChatModel(
|
||||
api_key=os.environ.get("DASHSCOPE_API_KEY"),
|
||||
model_name="qwen-max",
|
||||
enable_thinking=False,
|
||||
stream=True,
|
||||
),
|
||||
formatter=DashScopeChatFormatter(),
|
||||
toolkit=toolkit,
|
||||
memory=InMemoryMemory(),
|
||||
)
|
||||
user = UserAgent("User")
|
||||
|
||||
msg = None
|
||||
while True:
|
||||
msg = await user(msg)
|
||||
if msg.get_text_content() == "exit":
|
||||
break
|
||||
msg = await agent(msg)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
1
conversational_agents/chatbot/requirements.txt
Normal file
1
conversational_agents/chatbot/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
agentscope[full]>=1.0.5
|
||||
Reference in New Issue
Block a user