Agent方案
1.调模型的Http入参和出参
- 入参
{
"model": "MiniMax-M2.5",
"max_tokens": 2048,
"system": "你是一个乐于助人的助手。需要外部信息时请调用工具获取,不要凭空编造。",
"messages": [
{
"role": "user",
"content": "上海现在天气怎么样?现在几点了?"
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "call_function_y9wcrzaoal09_1",
"name": "get_weather",
"input": {
"city": "上海"
}
},
{
"type": "tool_use",
"id": "call_function_y9wcrzaoal09_2",
"name": "get_current_time",
"input": {}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "call_function_y9wcrzaoal09_1",
"content": "上海:晴,26℃,东南风 3 级,湿度 55%"
},
{
"type": "tool_result",
"tool_use_id": "call_function_y9wcrzaoal09_2",
"content": "2026-10-08 23:30:06"
}
]
}
],
"tools": [
{
"name": "get_weather",
"description": "查询指定城市的当前天气",
"input_schema": {
"required": [
"city"
],
"type": "object",
"properties": {
"city": {
"description": "城市名称,如:上海",
"type": "string"
}
}
}
},
{
"name": "get_current_time",
"description": "获取当前的日期和时间",
"input_schema": {
"properties": {},
"type": "object"
}
}
]
}
- 出参
text=, toolCalls=[ToolCall(id=call_function_jubdvduja8b1_1, name=get_weather, input={city=上海}), ToolCall(id=call_function_jubdvduja8b1_2, name=get_current_time, input={})], stopReason=tool_use
2.Model
模型对象,只包含配置信息,不包含动态变化的参数
Http调用模型的功能
3.Tool
工具对象
4.Message对象
上下文中的核心,包括user/assitant/system角色
5.AgentState
上下文对象,包含Message和sessionid
恢复和保存上下文功能
6.Agent
包含Model,Tool,AgentState,
6.1 ReAct流程
1.配置模型 2.根据sessionid恢复上下文 3.配置Tool 4.实例化Agent
5.开始循环
-
reasoning
调模型, 把返回的ToolCall写入上下文messages中(tool_use)。 -
acting
根据模型返回的tool_result执行工程代码逻辑,再把结果写入上下文messages (tool_result) -
maxIters
循环中判断次数,达到之后自动发一条assistant消息,告诉模型到达最大次数
6.循环结束后保存上下文

浙公网安备 33010602011771号