定义工具
RuntimeContext 包含运行 ID、智能体 ID、步骤索引、应用上下文以及原始工具调用。
创建智能体
通过 Phaseo Gateway 运行
完整示例
运行状态
RunResult 包含:
run:状态、ID、实际使用的模型、步骤上限、上下文和暂停状态steps:每轮模型调用、请求 ID、提供方、模型、结束原因、工具调用和用量messages:模型与工具的完整消息历史output:最终输出值usage:汇总令牌数,以及模型客户端提供的任何费用
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
创建一个同步 Rust 智能体,通过 Phaseo Gateway 调用本地工具。
use phaseo_agent::{define_tool, Tool};
use serde_json::json;
let lookup = define_tool(Tool::new(
"lookup_docs",
"Look up a Phaseo documentation topic",
json!({
"type": "object",
"properties": {
"topic": { "type": "string" }
},
"required": ["topic"]
}),
|input, context| {
Ok(json!({
"topic": input["topic"],
"run_id": context.run_id,
"found": true
}))
},
));
RuntimeContext 包含运行 ID、智能体 ID、步骤索引、应用上下文以及原始工具调用。
use phaseo_agent::{create_agent, AgentDefinition};
let agent = create_agent(
AgentDefinition::new("docs-agent", "openai/gpt-6-astra")
.instructions("Use lookup_docs when it helps. Finish with a concise answer.")
.max_steps(6)
.tool(lookup),
);
use phaseo_agent::{create_gateway_agent_client, RunOptions};
let mut client = create_gateway_agent_client("openai/gpt-6-astra")?;
let mut options = RunOptions::new("Explain when to use routing presets.");
options.context = serde_json::json!({
"workspace": "docs"
});
let result = agent.run(&mut client, options)?;
println!("{}", result.output);
use phaseo_agent::{
create_agent, create_gateway_agent_client, define_tool, AgentDefinition,
RunOptions, Tool,
};
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lookup = define_tool(Tool::new(
"lookup_docs",
"Look up a Phaseo documentation topic",
json!({
"type": "object",
"properties": {
"topic": { "type": "string" }
},
"required": ["topic"]
}),
|input, context| {
Ok(json!({
"topic": input["topic"],
"run_id": context.run_id,
"found": true
}))
},
));
let agent = create_agent(
AgentDefinition::new("docs-agent", "openai/gpt-6-astra")
.instructions("Use lookup_docs when helpful. Answer concisely.")
.max_steps(6)
.tool(lookup),
);
let mut client = create_gateway_agent_client("openai/gpt-6-astra")?;
let result = agent.run(
&mut client,
RunOptions::new("Explain when to use routing presets."),
)?;
println!("{}", result.output);
println!("steps: {}", result.run.step_count);
println!("tokens: {}", result.usage.total_tokens);
Ok(())
}
RunResult 包含:
run:状态、ID、实际使用的模型、步骤上限、上下文和暂停状态steps:每轮模型调用、请求 ID、提供方、模型、结束原因、工具调用和用量messages:模型与工具的完整消息历史output:最终输出值usage:汇总令牌数,以及模型客户端提供的任何费用