# ReActAgent **Repository Path**: Rysek/re-act-agent ## Basic Information - **Project Name**: ReActAgent - **Description**: 基于 ReAct(Reasoning and Acting)框架实现的智能对话 Agent,通过"思考 → 行动 → 观察"循环来解决用户问题。 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-23 - **Last Updated**: 2026-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ReAct Agent 基于 ReAct(Reasoning and Acting)框架实现的智能对话 Agent,通过"思考 → 行动 → 观察"循环来解决用户问题。 ## 简介 ReAct 是一种让大语言模型交替进行推理(Reasoning)和行动(Acting)的 Prompt 框架。本项目使用兼容 OpenAI 协议的 API(如硅基流动)驱动模型,逐步调用工具完成任务。 **循环流程:** ``` 用户问题 → Thought(思考)→ Action(选择工具)→ Action Input(工具参数)→ Observation(工具结果)→ ... → finish(最终答案) ``` ## 功能 | 工具 | 说明 | |------|------| | `weather_search` | 查询指定城市的天气(当前为 mock 数据) | | `calculator` | 执行数学表达式计算 | | `finish` | 输出最终答案,结束循环 | ## 快速开始 ### 安装依赖 ```bash pip install openai ``` ### 配置 在 `react_agent.py` 中填入你的 API Key 和 base_url: ```python API_KEY = "your-api-key-here" self.client = OpenAI( api_key=api_key, base_url="https://your-api-endpoint/v1", # 填入实际地址 ) ``` ### 运行 ```bash python react_agent.py ``` **示例输出:** ``` 用户:北京和上海的气温差多少度? [Step 1] LLM Reasoning... Thought: 我需要先查询北京的天气 Action: weather_search Action Input: 北京 [Observation] 大风,气温 10 到 15 度。 ... [Final Answer] 北京气温 10~15°C,上海气温 ...,相差约 X 度。 ``` ## 项目结构 ``` react_agent.py # ReAct Agent 核心实现 README.md # 项目说明 ``` ## 注意事项 - `calculator` 工具使用了 `eval`,已限制内置函数,但**生产环境建议替换为安全的计算沙箱**。 - `weather_search` 当前为 mock 数据,接入真实天气 API 时替换 `_weather_search` 方法即可。 - 默认最大迭代次数为 8,可通过 `max_iterations` 调整。 ## License MIT