本示例演示最简 LlmAgent:无城市时模型先澄清,指定城市后调用 get_weather_report 返回结构化天气结果。
- 两轮对话:泛问 → 具体城市
InMemorySessionService+Runner标准用法- 工具调用与
Tool Result打印清晰
root_agent (LlmAgent)
└── tools: get_weather_report
关键文件:
- 每轮使用新
session_id或按脚本逻辑创建会话 - 展示环境变量加载后与云端模型的一次完整 tool loop
- Python 3.12
git clone https://github.com/trpc-group/trpc-agent-python.git
cd trpc-agent-python
python3 -m venv .venv
source .venv/bin/activate
pip3 install -e .在 examples/quickstart/.env 中配置(或通过 export 设置):
TRPC_AGENT_API_KEYTRPC_AGENT_BASE_URLTRPC_AGENT_MODEL_NAME
cd examples/quickstart
python3 run_agent.py📝 User: What's the weather like today?
🤖 Assistant: Could you please specify the city...
📝 User: What's the current weather in Beijing?
🔧 [Invoke Tool: get_weather_report({'city': 'Beijing'})]
📊 [Tool Result: {'temperature': '25°C', 'condition': 'Sunny', 'humidity': '60%'}]
The current weather in Beijing is sunny ...
[END] quickstart (exit_code=0)
结论:符合本示例测试要求。
- 澄清与工具调用路径均出现;
exit_code=0,error.txt为空
- 新用户验证环境与 API Key 的首选入口
- 二次开发时对照的最小可运行骨架