#github.com/xulang-org/packages/agent
Xu 0.16.0 API
导入方式: agent #github.com/xulang-org/packages/agent
公开 API: 51 函数, 140 方法, 32 类型, 0 常量, 0 方法集
扩展包 `agent #github.com/xulang-org/packages/agent`,由模块 github.com/xulang-org/packages 提供。
github.com/xulang-org/packages · 1.17.2 · 安装与使用
struct LocalTool
pub struct LocalTool {
pub name string
pub description string
pub parameters_json string
pub handler fn(&string) string
}
用途
承载 name、description、parameters_json、handler 等属性的结构体。
公开字段
name string- 名字
description string- 字段(string)
parameters_json string- 字段(string)
handler fn(&string) string- 字段(函数值;类型 fn(&string) string)
struct Step
pub struct Step {
pub turn int
pub tool_name string
pub arguments_json string
pub output string
pub is_error bool
}
用途
承载 turn、tool_name、arguments_json、output、is_error 等属性的结构体。
公开字段
turn int- 字段(int)
tool_name string- 字段(string)
arguments_json string- 字段(string)
output string- 字段(string)
is_error bool- 字段(bool)
struct RunResult
pub struct RunResult {
pub content string
pub reasoning_content string
pub steps []Step
pub turns int
pub prompt_tokens int
pub completion_tokens int
pub total_tokens int
pub finish_reason string
}
用途
承载 content、reasoning_content、steps、turns、prompt_tokens 等属性的结构体。
公开字段
content string- 字段(string)
reasoning_content string- 字段(string)
steps []Step- 字段([]Step)
turns int- 字段(int)
prompt_tokens int- 字段(int)
completion_tokens int- 字段(int)
total_tokens int- 字段(int)
finish_reason string- 字段(string)
struct AgentEvent
pub struct AgentEvent {
pub kind string
pub turn int
pub text_delta string
pub reasoning_delta string
pub tool_name string
pub arguments_json string
pub tool_output string
pub is_error bool
pub finish_reason string
}
用途
承载 kind、turn、text_delta、reasoning_delta、tool_name 等属性的结构体。
公开字段
kind string- 类型标签
turn int- 字段(int)
text_delta string- 字段(string)
reasoning_delta string- 字段(string)
tool_name string- 字段(string)
arguments_json string- 字段(string)
tool_output string- 字段(string)
is_error bool- 字段(bool)
finish_reason string- 字段(string)
struct Skill
pub struct Skill {
pub name string
pub description string
pub body string
pub path string
}
用途
承载 name、description、body、path 等属性的结构体。
公开字段
name string- 名字
description string- 字段(string)
body string- 正文
path string- 文件系统路径
struct TraceSpan
pub struct TraceSpan {
pub trace_id string
pub kind string
pub name string
pub turn int
pub duration_ms int
pub tokens int
pub is_error bool
pub detail string
}
用途
承载 trace_id、kind、name、turn、duration_ms 等属性的结构体。
公开字段
trace_id string- 字段(string)
kind string- 类型标签
name string- 名字
turn int- 字段(int)
duration_ms int- 字段(int)
tokens int- 字段(int)
is_error bool- 字段(bool)
detail string- 字段(string)
struct AgentMemory
pub struct AgentMemory {
pub store rag.MemoryStore
}
用途
承载 store 等属性的结构体。
公开字段
store rag.MemoryStore- 字段(rag.MemoryStore)
struct WorkflowStepResult
pub struct WorkflowStepResult {
pub agent_name string
pub result RunResult
}
用途
承载 agent_name、result 等属性的结构体。
公开字段
agent_name string- 字段(string)
result RunResult- 字段(RunResult)
struct Agent
pub struct Agent {
pub client openai.Client
pub model string
pub system_prompt string
pub max_turns int
pub temperature f64
pub has_temperature bool
pub max_tokens int
pub max_total_tokens int
pub tool_choice string
pub response_format_json string
pub parallel_tools bool
pub context_max_tokens int
pub max_tool_output_chars int
pub progressive_skills bool
}
用途
承载 client、model、system_prompt、max_turns、temperature 等属性的结构体。
公开字段
client openai.Client- 字段(openai.Client)
model string- 字段(string)
system_prompt string- 字段(string)
max_turns int- 字段(int)
temperature f64- 字段(f64)
has_temperature bool- 字段(bool)
max_tokens int- 字段(int)
max_total_tokens int- 字段(int)
tool_choice string- 字段(string)
response_format_json string- 字段(string)
parallel_tools bool- 字段(bool)
context_max_tokens int- 字段(int)
max_tool_output_chars int- 字段(int)
progressive_skills bool- 字段(bool)
new_agent
pub fn new_agent(client openai.Client, model string) Agent
用途
构造 agent。
参数
client openai.Client- client(openai.Client)
model string- model(string)
返回值
Agent — 该类型的值
($&Agent) set_token_counter
pub fn (a $&Agent) set_token_counter(counter fn(&string) int)
用途
$&Agent 上的操作:设置 token counter。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
不返回值。
($&Agent) set_tool_hook
pub fn (a $&Agent) set_tool_hook(hook fn(&string, &string) string)
用途
$&Agent 上的操作:设置 tool hook。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) string- hook(函数值;类型 fn(&string, &string) string)
返回值
不返回值。
($&Agent) add_skill
pub fn (a $&Agent) add_skill(skill Skill)
用途
$&Agent 上的操作:执行 add skill 操作。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill- skill(Skill)
返回值
不返回值。
($&Agent) set_context_budget
pub fn (a $&Agent) set_context_budget(max_tokens int, max_tool_output_chars int)
用途
$&Agent 上的操作:设置 context budget。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_tokens int- max_tokens(int)
max_tool_output_chars int- max_tool_output_chars(int)
返回值
不返回值。
($&Agent) set_progressive_skills
pub fn (a $&Agent) set_progressive_skills(enabled bool)
用途
$&Agent 上的操作:设置 progressive skills。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&Agent) set_guardrails_policy
pub fn (a $&Agent) set_guardrails_policy(policy guardrails.Policy)
用途
$&Agent 上的操作:设置 guardrails policy。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
policy guardrails.Policy- policy(guardrails.Policy)
返回值
不返回值。
($&Agent) set_trace_hook
pub fn (a $&Agent) set_trace_hook(hook fn(TraceSpan))
用途
$&Agent 上的操作:设置 trace hook。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(TraceSpan)- hook(函数值;类型 fn(TraceSpan))
返回值
不返回值。
($&Agent) set_approval_hook
pub fn (a $&Agent) set_approval_hook(hook fn(&string, &string) bool)
用途
$&Agent 上的操作:设置 approval hook。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) bool- hook(函数值;类型 fn(&string, &string) bool)
返回值
不返回值。
($&Agent) set_system_prompt
pub fn (a $&Agent) set_system_prompt(prompt string)
用途
$&Agent 上的操作:设置 system prompt。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string- prompt(string)
返回值
不返回值。
($&Agent) set_max_turns
pub fn (a $&Agent) set_max_turns(max_turns int)
用途
$&Agent 上的操作:设置 max turns。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_turns int- max_turns(int)
返回值
不返回值。
($&Agent) set_temperature
pub fn (a $&Agent) set_temperature(t f64)
用途
$&Agent 上的操作:设置 temperature。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64- t(f64)
返回值
不返回值。
($&Agent) set_max_tokens
pub fn (a $&Agent) set_max_tokens(n int)
用途
$&Agent 上的操作:设置 max tokens。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&Agent) set_max_total_tokens
pub fn (a $&Agent) set_max_total_tokens(n int)
用途
$&Agent 上的操作:设置 max total tokens。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&Agent) set_tool_choice
pub fn (a $&Agent) set_tool_choice(choice string)
用途
$&Agent 上的操作:设置 tool choice。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
choice string- choice(string)
返回值
不返回值。
($&Agent) set_response_format
pub fn (a $&Agent) set_response_format(format_json string)
用途
$&Agent 上的操作:设置 response format。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
format_json string- format_json(string)
返回值
不返回值。
($&Agent) set_parallel_tools
pub fn (a $&Agent) set_parallel_tools(enabled bool)
用途
$&Agent 上的操作:设置 parallel tools。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&Agent) add_tool
pub fn (a $&Agent) add_tool(name string, description string, parameters_json string, handler fn(&string) string)
用途
$&Agent 上的操作:执行 add tool 操作。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
parameters_json string- parameters_json(string)
handler fn(&string) string- handler(函数值;类型 fn(&string) string)
返回值
不返回值。
from_mcp_tools
pub fn from_mcp_tools(tools &[]mcp.ToolInfo) []openai.ToolDef
用途
从 mcp tools 构造。
参数
tools &[]mcp.ToolInfo- tools(只读借用,调用方仍持有原值;类型 &[]mcp.ToolInfo)
返回值
[]openai.ToolDef — 切片结果
from_mcp_anthropic_tools
pub fn from_mcp_anthropic_tools(tools &[]mcp.ToolInfo) []anthropic.Tool
用途
从 mcp anthropic tools 构造。
参数
tools &[]mcp.ToolInfo- tools(只读借用,调用方仍持有原值;类型 &[]mcp.ToolInfo)
返回值
[]anthropic.Tool — 切片结果
struct Session
pub struct Session {
pub agent Agent
}
用途
承载 agent 等属性的结构体。
公开字段
agent Agent- 字段(Agent)
new_session
pub fn new_session(agent Agent) Session
用途
构造 session。
参数
agent Agent- agent(Agent)
返回值
Session — 该类型的值
($&Session) clear
pub fn (s $&Session) clear()
用途
清空所有已缓冲或存储的数据项与内部状态。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
不返回值。
(&Session) history
pub fn (s &Session) history() []openai.Message
用途
在 &Session 上执行 history 操作。
参数
s &Session- 本次调用使用的
Session 实例;以只读借用传入,调用方仍持有实例。
返回值
[]openai.Message — 切片结果
($&Session) send
pub fn (s $&Session) send(user_prompt string) RunResult
用途
在 $&Session 上执行 send 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
($&Session) send_with_mcp
pub fn (s $&Session) send_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
$&Session 上的操作:执行 send with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
($&Session) send_with_stdio_mcp
pub fn (s $&Session) send_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
$&Session 上的操作:执行 send with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
($&Session) send_stream
pub fn (s $&Session) send_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
$&Session 上的操作:执行 send stream 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
($&Session) send_stream_with_mcp
pub fn (s $&Session) send_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
$&Session 上的操作:执行 send stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&Session- 本次调用使用的
Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&Agent) run
pub fn (a &Agent) run(user_prompt string) RunResult
用途
&Agent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
(&Agent) run_with_mcp
pub fn (a &Agent) run_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
&Agent 上的操作:执行 run with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
(&Agent) run_with_stdio_mcp
pub fn (a &Agent) run_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
&Agent 上的操作:执行 run with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
(&Agent) run_stream
pub fn (a &Agent) run_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
&Agent 上的操作:运行流。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&Agent) run_stream_with_mcp
pub fn (a &Agent) run_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
&Agent 上的操作:执行 run stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&Agent) run_stream_with_stdio_mcp
pub fn (a &Agent) run_stream_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient, on_event fn(AgentEvent) bool) RunResult
用途
&Agent 上的操作:执行 run stream with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct AnthropicAgent
pub struct AnthropicAgent {
pub client anthropic.Client
pub model string
pub system_prompt string
pub max_turns int
pub max_tokens int
pub max_total_tokens int
pub temperature f64
pub has_temperature bool
pub thinking_budget_tokens int
pub parallel_tools bool
pub context_max_tokens int
pub max_tool_output_chars int
pub progressive_skills bool
}
用途
承载 client、model、system_prompt、max_turns、max_tokens 等属性的结构体。
公开字段
client anthropic.Client- 字段(anthropic.Client)
model string- 字段(string)
system_prompt string- 字段(string)
max_turns int- 字段(int)
max_tokens int- 字段(int)
max_total_tokens int- 字段(int)
temperature f64- 字段(f64)
has_temperature bool- 字段(bool)
thinking_budget_tokens int- 字段(int)
parallel_tools bool- 字段(bool)
context_max_tokens int- 字段(int)
max_tool_output_chars int- 字段(int)
progressive_skills bool- 字段(bool)
new_anthropic_agent
pub fn new_anthropic_agent(client anthropic.Client, model string) AnthropicAgent
用途
构造 anthropic agent。
参数
client anthropic.Client- client(anthropic.Client)
model string- model(string)
返回值
AnthropicAgent — 该类型的值
($&AnthropicAgent) set_token_counter
pub fn (a $&AnthropicAgent) set_token_counter(counter fn(&string) int)
用途
$&AnthropicAgent 上的操作:设置 token counter。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
不返回值。
($&AnthropicAgent) set_tool_hook
pub fn (a $&AnthropicAgent) set_tool_hook(hook fn(&string, &string) string)
用途
$&AnthropicAgent 上的操作:设置 tool hook。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) string- hook(函数值;类型 fn(&string, &string) string)
返回值
不返回值。
($&AnthropicAgent) add_skill
pub fn (a $&AnthropicAgent) add_skill(skill Skill)
用途
$&AnthropicAgent 上的操作:执行 add skill 操作。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill- skill(Skill)
返回值
不返回值。
($&AnthropicAgent) load_skills_dir
pub fn (a $&AnthropicAgent) load_skills_dir(dir_path string) int
用途
$&AnthropicAgent 上的操作:执行 load skills dir 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dir_path string- dir_path(string)
返回值
int — 该类型的值
($&AnthropicAgent) set_progressive_skills
pub fn (a $&AnthropicAgent) set_progressive_skills(enabled bool)
用途
$&AnthropicAgent 上的操作:设置 progressive skills。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&AnthropicAgent) set_context_budget
pub fn (a $&AnthropicAgent) set_context_budget(max_tokens int, max_tool_output_chars int)
用途
$&AnthropicAgent 上的操作:设置 context budget。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_tokens int- max_tokens(int)
max_tool_output_chars int- max_tool_output_chars(int)
返回值
不返回值。
($&AnthropicAgent) set_guardrails_policy
pub fn (a $&AnthropicAgent) set_guardrails_policy(policy guardrails.Policy)
用途
$&AnthropicAgent 上的操作:设置 guardrails policy。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
policy guardrails.Policy- policy(guardrails.Policy)
返回值
不返回值。
($&AnthropicAgent) set_trace_hook
pub fn (a $&AnthropicAgent) set_trace_hook(hook fn(TraceSpan))
用途
$&AnthropicAgent 上的操作:设置 trace hook。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(TraceSpan)- hook(函数值;类型 fn(TraceSpan))
返回值
不返回值。
($&AnthropicAgent) set_approval_hook
pub fn (a $&AnthropicAgent) set_approval_hook(hook fn(&string, &string) bool)
用途
$&AnthropicAgent 上的操作:设置 approval hook。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) bool- hook(函数值;类型 fn(&string, &string) bool)
返回值
不返回值。
($&AnthropicAgent) set_system_prompt
pub fn (a $&AnthropicAgent) set_system_prompt(prompt string)
用途
$&AnthropicAgent 上的操作:设置 system prompt。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string- prompt(string)
返回值
不返回值。
($&AnthropicAgent) set_max_turns
pub fn (a $&AnthropicAgent) set_max_turns(max_turns int)
用途
$&AnthropicAgent 上的操作:设置 max turns。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_turns int- max_turns(int)
返回值
不返回值。
($&AnthropicAgent) set_max_tokens
pub fn (a $&AnthropicAgent) set_max_tokens(n int)
用途
$&AnthropicAgent 上的操作:设置 max tokens。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&AnthropicAgent) set_max_total_tokens
pub fn (a $&AnthropicAgent) set_max_total_tokens(n int)
用途
$&AnthropicAgent 上的操作:设置 max total tokens。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&AnthropicAgent) set_temperature
pub fn (a $&AnthropicAgent) set_temperature(t f64)
用途
$&AnthropicAgent 上的操作:设置 temperature。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64- t(f64)
返回值
不返回值。
($&AnthropicAgent) set_thinking_budget
pub fn (a $&AnthropicAgent) set_thinking_budget(tokens int)
用途
$&AnthropicAgent 上的操作:设置 thinking budget。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
tokens int- tokens(int)
返回值
不返回值。
($&AnthropicAgent) set_parallel_tools
pub fn (a $&AnthropicAgent) set_parallel_tools(enabled bool)
用途
$&AnthropicAgent 上的操作:设置 parallel tools。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&AnthropicAgent) add_tool
pub fn (a $&AnthropicAgent) add_tool(name string, description string, parameters_json string, handler fn(&string) string)
用途
$&AnthropicAgent 上的操作:执行 add tool 操作。
参数
a $&AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
parameters_json string- parameters_json(string)
handler fn(&string) string- handler(函数值;类型 fn(&string) string)
返回值
不返回值。
compact_anthropic_messages_with
pub fn compact_anthropic_messages_with(messages &[]anthropic.Message, max_tokens int, keep_recent int, counter fn(&string) int) []anthropic.Message
用途
执行 compact anthropic messages with 操作。
参数
messages &[]anthropic.Message- messages(只读借用,调用方仍持有原值;类型 &[]anthropic.Message)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
[]anthropic.Message — 切片结果
compact_anthropic_messages
pub fn compact_anthropic_messages(messages &[]anthropic.Message, max_tokens int, keep_recent int) []anthropic.Message
用途
执行 compact anthropic messages 操作。
参数
messages &[]anthropic.Message- messages(只读借用,调用方仍持有原值;类型 &[]anthropic.Message)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
返回值
[]anthropic.Message — 切片结果
(&AnthropicAgent) run
pub fn (a &AnthropicAgent) run(user_prompt string) RunResult
用途
&AnthropicAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
a &AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
(&AnthropicAgent) run_with_mcp
pub fn (a &AnthropicAgent) run_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
&AnthropicAgent 上的操作:执行 run with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
(&AnthropicAgent) run_stream
pub fn (a &AnthropicAgent) run_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
&AnthropicAgent 上的操作:运行流。失败时抛出错误,调用方需处理或继续传播。
参数
a &AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&AnthropicAgent) run_stream_with_mcp
pub fn (a &AnthropicAgent) run_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
&AnthropicAgent 上的操作:执行 run stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &AnthropicAgent- 本次调用使用的
AnthropicAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct AnthropicSession
pub struct AnthropicSession {
pub agent AnthropicAgent
}
用途
承载 agent 等属性的结构体。
公开字段
agent AnthropicAgent- 字段(AnthropicAgent)
new_anthropic_session
pub fn new_anthropic_session(agent AnthropicAgent) AnthropicSession
用途
构造 anthropic session。
参数
agent AnthropicAgent- agent(AnthropicAgent)
返回值
AnthropicSession — 该类型的值
($&AnthropicSession) clear
pub fn (s $&AnthropicSession) clear()
用途
清空所有已缓冲或存储的数据项与内部状态。
参数
s $&AnthropicSession- 本次调用使用的
AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
不返回值。
(&AnthropicSession) history
pub fn (s &AnthropicSession) history() []anthropic.Message
用途
在 &AnthropicSession 上执行 history 操作。
参数
s &AnthropicSession- 本次调用使用的
AnthropicSession 实例;以只读借用传入,调用方仍持有实例。
返回值
[]anthropic.Message — 切片结果
($&AnthropicSession) send
pub fn (s $&AnthropicSession) send(user_prompt string) RunResult
用途
在 $&AnthropicSession 上执行 send 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&AnthropicSession- 本次调用使用的
AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
($&AnthropicSession) send_with_mcp
pub fn (s $&AnthropicSession) send_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
$&AnthropicSession 上的操作:执行 send with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&AnthropicSession- 本次调用使用的
AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
($&AnthropicSession) send_stream
pub fn (s $&AnthropicSession) send_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
$&AnthropicSession 上的操作:执行 send stream 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&AnthropicSession- 本次调用使用的
AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
($&AnthropicSession) send_stream_with_mcp
pub fn (s $&AnthropicSession) send_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
$&AnthropicSession 上的操作:执行 send stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&AnthropicSession- 本次调用使用的
AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct GeminiAgent
pub struct GeminiAgent {
pub client gemini.Client
pub model string
pub system_prompt string
pub max_turns int
pub max_tokens int
pub max_total_tokens int
pub temperature f64
pub has_temperature bool
pub thinking_budget int
pub parallel_tools bool
pub context_max_tokens int
pub max_tool_output_chars int
pub progressive_skills bool
}
用途
承载 client、model、system_prompt、max_turns、max_tokens 等属性的结构体。
公开字段
client gemini.Client- 字段(gemini.Client)
model string- 字段(string)
system_prompt string- 字段(string)
max_turns int- 字段(int)
max_tokens int- 字段(int)
max_total_tokens int- 字段(int)
temperature f64- 字段(f64)
has_temperature bool- 字段(bool)
thinking_budget int- 字段(int)
parallel_tools bool- 字段(bool)
context_max_tokens int- 字段(int)
max_tool_output_chars int- 字段(int)
progressive_skills bool- 字段(bool)
new_gemini_agent
pub fn new_gemini_agent(client gemini.Client, model string) GeminiAgent
用途
构造 gemini agent。
参数
client gemini.Client- client(gemini.Client)
model string- model(string)
返回值
GeminiAgent — 该类型的值
($&GeminiAgent) set_token_counter
pub fn (a $&GeminiAgent) set_token_counter(counter fn(&string) int)
用途
$&GeminiAgent 上的操作:设置 token counter。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
不返回值。
($&GeminiAgent) set_tool_hook
pub fn (a $&GeminiAgent) set_tool_hook(hook fn(&string, &string) string)
用途
$&GeminiAgent 上的操作:设置 tool hook。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) string- hook(函数值;类型 fn(&string, &string) string)
返回值
不返回值。
($&GeminiAgent) add_skill
pub fn (a $&GeminiAgent) add_skill(skill Skill)
用途
$&GeminiAgent 上的操作:执行 add skill 操作。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill- skill(Skill)
返回值
不返回值。
($&GeminiAgent) load_skills_dir
pub fn (a $&GeminiAgent) load_skills_dir(dir_path string) int
用途
$&GeminiAgent 上的操作:执行 load skills dir 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dir_path string- dir_path(string)
返回值
int — 该类型的值
($&GeminiAgent) set_progressive_skills
pub fn (a $&GeminiAgent) set_progressive_skills(enabled bool)
用途
$&GeminiAgent 上的操作:设置 progressive skills。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&GeminiAgent) set_context_budget
pub fn (a $&GeminiAgent) set_context_budget(max_tokens int, max_tool_output_chars int)
用途
$&GeminiAgent 上的操作:设置 context budget。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_tokens int- max_tokens(int)
max_tool_output_chars int- max_tool_output_chars(int)
返回值
不返回值。
($&GeminiAgent) set_guardrails_policy
pub fn (a $&GeminiAgent) set_guardrails_policy(policy guardrails.Policy)
用途
$&GeminiAgent 上的操作:设置 guardrails policy。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
policy guardrails.Policy- policy(guardrails.Policy)
返回值
不返回值。
($&GeminiAgent) set_trace_hook
pub fn (a $&GeminiAgent) set_trace_hook(hook fn(TraceSpan))
用途
$&GeminiAgent 上的操作:设置 trace hook。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(TraceSpan)- hook(函数值;类型 fn(TraceSpan))
返回值
不返回值。
($&GeminiAgent) set_approval_hook
pub fn (a $&GeminiAgent) set_approval_hook(hook fn(&string, &string) bool)
用途
$&GeminiAgent 上的操作:设置 approval hook。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) bool- hook(函数值;类型 fn(&string, &string) bool)
返回值
不返回值。
($&GeminiAgent) set_system_prompt
pub fn (a $&GeminiAgent) set_system_prompt(prompt string)
用途
$&GeminiAgent 上的操作:设置 system prompt。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string- prompt(string)
返回值
不返回值。
($&GeminiAgent) set_max_turns
pub fn (a $&GeminiAgent) set_max_turns(max_turns int)
用途
$&GeminiAgent 上的操作:设置 max turns。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_turns int- max_turns(int)
返回值
不返回值。
($&GeminiAgent) set_max_tokens
pub fn (a $&GeminiAgent) set_max_tokens(n int)
用途
$&GeminiAgent 上的操作:设置 max tokens。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&GeminiAgent) set_max_total_tokens
pub fn (a $&GeminiAgent) set_max_total_tokens(n int)
用途
$&GeminiAgent 上的操作:设置 max total tokens。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&GeminiAgent) set_temperature
pub fn (a $&GeminiAgent) set_temperature(t f64)
用途
$&GeminiAgent 上的操作:设置 temperature。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64- t(f64)
返回值
不返回值。
($&GeminiAgent) set_thinking_budget
pub fn (a $&GeminiAgent) set_thinking_budget(tokens int)
用途
$&GeminiAgent 上的操作:设置 thinking budget。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
tokens int- tokens(int)
返回值
不返回值。
($&GeminiAgent) set_parallel_tools
pub fn (a $&GeminiAgent) set_parallel_tools(enabled bool)
用途
$&GeminiAgent 上的操作:设置 parallel tools。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&GeminiAgent) add_tool
pub fn (a $&GeminiAgent) add_tool(name string, description string, parameters_json string, handler fn(&string) string)
用途
$&GeminiAgent 上的操作:执行 add tool 操作。
参数
a $&GeminiAgent- 本次调用使用的
GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
parameters_json string- parameters_json(string)
handler fn(&string) string- handler(函数值;类型 fn(&string) string)
返回值
不返回值。
from_mcp_gemini_tools
pub fn from_mcp_gemini_tools(tools &[]mcp.ToolInfo) []gemini.FunctionDecl
用途
从 mcp gemini tools 构造。
参数
tools &[]mcp.ToolInfo- tools(只读借用,调用方仍持有原值;类型 &[]mcp.ToolInfo)
返回值
[]gemini.FunctionDecl — 切片结果
compact_gemini_contents_with
pub fn compact_gemini_contents_with(contents &[]gemini.Content, max_tokens int, keep_recent int, counter fn(&string) int) []gemini.Content
用途
执行 compact gemini contents with 操作。
参数
contents &[]gemini.Content- contents(只读借用,调用方仍持有原值;类型 &[]gemini.Content)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
[]gemini.Content — 切片结果
compact_gemini_contents
pub fn compact_gemini_contents(contents &[]gemini.Content, max_tokens int, keep_recent int) []gemini.Content
用途
执行 compact gemini contents 操作。
参数
contents &[]gemini.Content- contents(只读借用,调用方仍持有原值;类型 &[]gemini.Content)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
返回值
[]gemini.Content — 切片结果
(&GeminiAgent) run
pub fn (a &GeminiAgent) run(user_prompt string) RunResult
用途
&GeminiAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
(&GeminiAgent) run_with_mcp
pub fn (a &GeminiAgent) run_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
&GeminiAgent 上的操作:执行 run with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
(&GeminiAgent) run_with_stdio_mcp
pub fn (a &GeminiAgent) run_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
&GeminiAgent 上的操作:执行 run with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
(&GeminiAgent) run_stream
pub fn (a &GeminiAgent) run_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
&GeminiAgent 上的操作:运行流。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&GeminiAgent) run_stream_with_mcp
pub fn (a &GeminiAgent) run_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
&GeminiAgent 上的操作:执行 run stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&GeminiAgent) run_stream_with_stdio_mcp
pub fn (a &GeminiAgent) run_stream_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient, on_event fn(AgentEvent) bool) RunResult
用途
&GeminiAgent 上的操作:执行 run stream with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &GeminiAgent- 本次调用使用的
GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct GeminiSession
pub struct GeminiSession {
pub agent GeminiAgent
}
用途
承载 agent 等属性的结构体。
公开字段
agent GeminiAgent- 字段(GeminiAgent)
new_gemini_session
pub fn new_gemini_session(agent GeminiAgent) GeminiSession
用途
构造 gemini session。
参数
agent GeminiAgent- agent(GeminiAgent)
返回值
GeminiSession — 该类型的值
($&GeminiSession) clear
pub fn (s $&GeminiSession) clear()
用途
清空所有已缓冲或存储的数据项与内部状态。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
不返回值。
(&GeminiSession) history
pub fn (s &GeminiSession) history() []gemini.Content
用途
在 &GeminiSession 上执行 history 操作。
参数
s &GeminiSession- 本次调用使用的
GeminiSession 实例;以只读借用传入,调用方仍持有实例。
返回值
[]gemini.Content — 切片结果
($&GeminiSession) send
pub fn (s $&GeminiSession) send(user_prompt string) RunResult
用途
在 $&GeminiSession 上执行 send 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
($&GeminiSession) send_with_mcp
pub fn (s $&GeminiSession) send_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
$&GeminiSession 上的操作:执行 send with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
($&GeminiSession) send_with_stdio_mcp
pub fn (s $&GeminiSession) send_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
$&GeminiSession 上的操作:执行 send with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
($&GeminiSession) send_stream
pub fn (s $&GeminiSession) send_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
$&GeminiSession 上的操作:执行 send stream 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
($&GeminiSession) send_stream_with_mcp
pub fn (s $&GeminiSession) send_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
$&GeminiSession 上的操作:执行 send stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&GeminiSession- 本次调用使用的
GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct ResponsesAgent
pub struct ResponsesAgent {
pub client openai.Client
pub model string
pub instructions string
pub max_turns int
pub temperature f64
pub has_temperature bool
pub max_output_tokens int
pub max_total_tokens int
pub tool_choice string
pub parallel_tools bool
pub context_max_tokens int
pub max_tool_output_chars int
pub progressive_skills bool
}
用途
承载 client、model、instructions、max_turns、temperature 等属性的结构体。
公开字段
client openai.Client- 字段(openai.Client)
model string- 字段(string)
instructions string- 字段(string)
max_turns int- 字段(int)
temperature f64- 字段(f64)
has_temperature bool- 字段(bool)
max_output_tokens int- 字段(int)
max_total_tokens int- 字段(int)
tool_choice string- 字段(string)
parallel_tools bool- 字段(bool)
context_max_tokens int- 字段(int)
max_tool_output_chars int- 字段(int)
progressive_skills bool- 字段(bool)
new_responses_agent
pub fn new_responses_agent(client openai.Client, model string) ResponsesAgent
用途
构造 responses agent。
参数
client openai.Client- client(openai.Client)
model string- model(string)
返回值
ResponsesAgent — 该类型的值
($&ResponsesAgent) set_token_counter
pub fn (a $&ResponsesAgent) set_token_counter(counter fn(&string) int)
用途
$&ResponsesAgent 上的操作:设置 token counter。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
不返回值。
($&ResponsesAgent) set_instructions
pub fn (a $&ResponsesAgent) set_instructions(s string)
用途
$&ResponsesAgent 上的操作:设置 instructions。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
s string- 源字符串(string)
返回值
不返回值。
($&ResponsesAgent) set_max_turns
pub fn (a $&ResponsesAgent) set_max_turns(n int)
用途
$&ResponsesAgent 上的操作:设置 max turns。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&ResponsesAgent) set_temperature
pub fn (a $&ResponsesAgent) set_temperature(t f64)
用途
$&ResponsesAgent 上的操作:设置 temperature。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64- t(f64)
返回值
不返回值。
($&ResponsesAgent) set_max_output_tokens
pub fn (a $&ResponsesAgent) set_max_output_tokens(n int)
用途
$&ResponsesAgent 上的操作:设置 max output tokens。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&ResponsesAgent) set_max_total_tokens
pub fn (a $&ResponsesAgent) set_max_total_tokens(n int)
用途
$&ResponsesAgent 上的操作:设置 max total tokens。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int- 数量、长度或上限(int)
返回值
不返回值。
($&ResponsesAgent) set_tool_choice
pub fn (a $&ResponsesAgent) set_tool_choice(c string)
用途
$&ResponsesAgent 上的操作:设置 tool choice。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
c string- 字节或字符码(string)
返回值
不返回值。
($&ResponsesAgent) set_parallel_tools
pub fn (a $&ResponsesAgent) set_parallel_tools(enabled bool)
用途
$&ResponsesAgent 上的操作:设置 parallel tools。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&ResponsesAgent) set_tool_hook
pub fn (a $&ResponsesAgent) set_tool_hook(hook fn(&string, &string) string)
用途
$&ResponsesAgent 上的操作:设置 tool hook。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) string- hook(函数值;类型 fn(&string, &string) string)
返回值
不返回值。
($&ResponsesAgent) add_skill
pub fn (a $&ResponsesAgent) add_skill(skill Skill)
用途
$&ResponsesAgent 上的操作:执行 add skill 操作。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill- skill(Skill)
返回值
不返回值。
($&ResponsesAgent) load_skills_dir
pub fn (a $&ResponsesAgent) load_skills_dir(dir_path string) int
用途
$&ResponsesAgent 上的操作:执行 load skills dir 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dir_path string- dir_path(string)
返回值
int — 该类型的值
($&ResponsesAgent) set_progressive_skills
pub fn (a $&ResponsesAgent) set_progressive_skills(enabled bool)
用途
$&ResponsesAgent 上的操作:设置 progressive skills。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool- enabled(bool)
返回值
不返回值。
($&ResponsesAgent) set_context_budget
pub fn (a $&ResponsesAgent) set_context_budget(max_tokens int, max_tool_output_chars int)
用途
$&ResponsesAgent 上的操作:设置 context budget。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max_tokens int- max_tokens(int)
max_tool_output_chars int- max_tool_output_chars(int)
返回值
不返回值。
($&ResponsesAgent) set_guardrails_policy
pub fn (a $&ResponsesAgent) set_guardrails_policy(policy guardrails.Policy)
用途
$&ResponsesAgent 上的操作:设置 guardrails policy。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
policy guardrails.Policy- policy(guardrails.Policy)
返回值
不返回值。
($&ResponsesAgent) set_trace_hook
pub fn (a $&ResponsesAgent) set_trace_hook(hook fn(TraceSpan))
用途
$&ResponsesAgent 上的操作:设置 trace hook。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(TraceSpan)- hook(函数值;类型 fn(TraceSpan))
返回值
不返回值。
($&ResponsesAgent) set_approval_hook
pub fn (a $&ResponsesAgent) set_approval_hook(hook fn(&string, &string) bool)
用途
$&ResponsesAgent 上的操作:设置 approval hook。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
hook fn(&string, &string) bool- hook(函数值;类型 fn(&string, &string) bool)
返回值
不返回值。
($&ResponsesAgent) add_tool
pub fn (a $&ResponsesAgent) add_tool(name string, description string, parameters_json string, handler fn(&string) string)
用途
$&ResponsesAgent 上的操作:执行 add tool 操作。
参数
a $&ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
parameters_json string- parameters_json(string)
handler fn(&string) string- handler(函数值;类型 fn(&string) string)
返回值
不返回值。
(&ResponsesAgent) run
pub fn (a &ResponsesAgent) run(user_prompt string) RunResult
用途
&ResponsesAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
a &ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
(&ResponsesAgent) run_with_mcp
pub fn (a &ResponsesAgent) run_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
&ResponsesAgent 上的操作:执行 run with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
(&ResponsesAgent) run_with_stdio_mcp
pub fn (a &ResponsesAgent) run_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
&ResponsesAgent 上的操作:执行 run with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
(&ResponsesAgent) run_stream
pub fn (a &ResponsesAgent) run_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
&ResponsesAgent 上的操作:运行流。失败时抛出错误,调用方需处理或继续传播。
参数
a &ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
(&ResponsesAgent) run_stream_with_mcp
pub fn (a &ResponsesAgent) run_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
&ResponsesAgent 上的操作:执行 run stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &ResponsesAgent- 本次调用使用的
ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
struct ResponsesSession
pub struct ResponsesSession {
pub agent ResponsesAgent
pub prev_response_id string
}
用途
承载 agent、prev_response_id 等属性的结构体。
公开字段
agent ResponsesAgent- 字段(ResponsesAgent)
prev_response_id string- 字段(string)
new_responses_session
pub fn new_responses_session(agent ResponsesAgent) ResponsesSession
用途
构造 responses session。
参数
agent ResponsesAgent- agent(ResponsesAgent)
返回值
ResponsesSession — 该类型的值
($&ResponsesSession) clear
pub fn (s $&ResponsesSession) clear()
用途
清空所有已缓冲或存储的数据项与内部状态。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
不返回值。
(&ResponsesSession) last_response_id
pub fn (s &ResponsesSession) last_response_id() string
用途
&ResponsesSession 上的操作:执行 last response id 操作。
参数
s &ResponsesSession- 本次调用使用的
ResponsesSession 实例;以只读借用传入,调用方仍持有实例。
返回值
string — 结果字符串
($&ResponsesSession) send
pub fn (s $&ResponsesSession) send(user_prompt string) RunResult
用途
在 $&ResponsesSession 上执行 send 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
返回值
RunResult — 该类型的值
($&ResponsesSession) send_with_mcp
pub fn (s $&ResponsesSession) send_with_mcp(user_prompt string, mc $&mcp.Client) RunResult
用途
$&ResponsesSession 上的操作:执行 send with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
返回值
RunResult — 该类型的值
($&ResponsesSession) send_with_stdio_mcp
pub fn (s $&ResponsesSession) send_with_stdio_mcp(user_prompt string, mc $&mcp.StdioClient) RunResult
用途
$&ResponsesSession 上的操作:执行 send with stdio mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.StdioClient- mc(独占借用,可修改原值;类型 $&mcp.StdioClient)
返回值
RunResult — 该类型的值
($&ResponsesSession) send_stream
pub fn (s $&ResponsesSession) send_stream(user_prompt string, on_event fn(AgentEvent) bool) RunResult
用途
$&ResponsesSession 上的操作:执行 send stream 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
($&ResponsesSession) send_stream_with_mcp
pub fn (s $&ResponsesSession) send_stream_with_mcp(user_prompt string, mc $&mcp.Client, on_event fn(AgentEvent) bool) RunResult
用途
$&ResponsesSession 上的操作:执行 send stream with mcp 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s $&ResponsesSession- 本次调用使用的
ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
user_prompt string- user_prompt(string)
mc $&mcp.Client- mc(独占借用,可修改原值;类型 $&mcp.Client)
on_event fn(AgentEvent) bool- on_event(函数值;类型 fn(AgentEvent) bool)
返回值
RunResult — 该类型的值
parse_skill_markdown
pub fn parse_skill_markdown(raw &string, path string) Skill
用途
解析为 skill markdown。
参数
raw &string- raw(只读借用,调用方仍持有原值;类型 &string)
path string- 文件系统路径(string)
返回值
Skill — 该类型的值
load_skill_file
pub fn load_skill_file(path string) Skill
用途
执行 load skill file 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
返回值
Skill — 该类型的值
format_skills_prompt
pub fn format_skills_prompt(skills &[]Skill, user_prompt &string) string
用途
格式化为 skills prompt。
参数
skills &[]Skill- skills(只读借用,调用方仍持有原值;类型 &[]Skill)
user_prompt &string- user_prompt(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
format_skills_catalog
pub fn format_skills_catalog(skills &[]Skill) string
用途
格式化为 skills catalog。
参数
skills &[]Skill- skills(只读借用,调用方仍持有原值;类型 &[]Skill)
返回值
string — 结果字符串
lookup_skill_body
pub fn lookup_skill_body(skills &[]Skill, name &string) string
用途
执行 lookup skill body 操作。
参数
skills &[]Skill- skills(只读借用,调用方仍持有原值;类型 &[]Skill)
name &string- 名字(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
new_memory
pub fn new_memory(dim int) AgentMemory
用途
构造 memory。
参数
dim int- dim(int)
返回值
AgentMemory — 该类型的值
($&AgentMemory) remember
pub fn (m $&AgentMemory) remember(text string, tag string, embedding &[]f64) string
用途
在 $&AgentMemory 上执行 remember 操作。失败时抛出错误,调用方需处理或继续传播。
参数
m $&AgentMemory- 本次调用使用的
AgentMemory 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
text string- 文本(string)
tag string- tag(string)
embedding &[]f64- embedding(只读借用,调用方仍持有原值;类型 &[]f64)
返回值
string — 结果字符串
(&AgentMemory) recall
pub fn (m &AgentMemory) recall(query string, query_emb &[]f64, top_k int) []rag.SearchHit
用途
在 &AgentMemory 上执行 recall 操作。
参数
m &AgentMemory- 本次调用使用的
AgentMemory 实例;以只读借用传入,调用方仍持有实例。
query string- query(string)
query_emb &[]f64- query_emb(只读借用,调用方仍持有原值;类型 &[]f64)
top_k int- top_k(int)
返回值
[]rag.SearchHit — 切片结果
(&AgentMemory) format_memories
pub fn (m &AgentMemory) format_memories(hits &[]rag.SearchHit) string
用途
&AgentMemory 上的操作:格式化为 memories。
参数
m &AgentMemory- 本次调用使用的
AgentMemory 实例;以只读借用传入,调用方仍持有实例。
hits &[]rag.SearchHit- hits(只读借用,调用方仍持有原值;类型 &[]rag.SearchHit)
返回值
string — 结果字符串
($&AgentMemory) forget
pub fn (m $&AgentMemory) forget(id string) bool
用途
在 $&AgentMemory 上执行 forget 操作。
参数
m $&AgentMemory- 本次调用使用的
AgentMemory 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string- id(string)
返回值
bool — 是否成立
($&AgentMemory) update
pub fn (m $&AgentMemory) update(id string, text string, tag string, embedding &[]f64) bool
用途
$&AgentMemory 上的操作:更新。失败时抛出错误,调用方需处理或继续传播。
参数
m $&AgentMemory- 本次调用使用的
AgentMemory 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string- id(string)
text string- 文本(string)
tag string- tag(string)
embedding &[]f64- embedding(只读借用,调用方仍持有原值;类型 &[]f64)
返回值
bool — 是否成立
(&AgentMemory) save_json
pub fn (m &AgentMemory) save_json(path string) int
用途
&AgentMemory 上的操作:执行 save json 操作。失败时抛出错误,调用方需处理或继续传播。
参数
m &AgentMemory- 本次调用使用的
AgentMemory 实例;以只读借用传入,调用方仍持有实例。
path string- 文件系统路径(string)
返回值
int — 该类型的值
load_memory_json
pub fn load_memory_json(path string) AgentMemory
用途
执行 load memory json 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
返回值
AgentMemory — 该类型的值
(&AgentMemory) save_sqlite
pub fn (m &AgentMemory) save_sqlite(path string) int
用途
&AgentMemory 上的操作:执行 save sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
m &AgentMemory- 本次调用使用的
AgentMemory 实例;以只读借用传入,调用方仍持有实例。
path string- 文件系统路径(string)
返回值
int — 该类型的值
load_memory_sqlite
pub fn load_memory_sqlite(path string) AgentMemory
用途
执行 load memory sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
返回值
AgentMemory — 该类型的值
estimate_tokens
pub fn estimate_tokens(text &string) int
用途
执行 estimate tokens 操作。
参数
text &string- 文本(只读借用,调用方仍持有原值;类型 &string)
返回值
int — 该类型的值
compact_messages_with
pub fn compact_messages_with(messages &[]openai.Message, max_tokens int, keep_recent int, counter fn(&string) int) []openai.Message
用途
执行 compact messages with 操作。
参数
messages &[]openai.Message- messages(只读借用,调用方仍持有原值;类型 &[]openai.Message)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
counter fn(&string) int- counter(函数值;类型 fn(&string) int)
返回值
[]openai.Message — 切片结果
compact_messages
pub fn compact_messages(messages &[]openai.Message, max_tokens int, keep_recent int) []openai.Message
用途
执行 compact messages 操作。
参数
messages &[]openai.Message- messages(只读借用,调用方仍持有原值;类型 &[]openai.Message)
max_tokens int- max_tokens(int)
keep_recent int- keep_recent(int)
返回值
[]openai.Message — 切片结果
summarize_messages_openai
pub fn summarize_messages_openai(client &openai.Client, model string, messages &[]openai.Message, keep_recent int) []openai.Message
用途
执行 summarize messages openai 操作。失败时抛出错误,调用方需处理或继续传播。
参数
client &openai.Client- client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string- model(string)
messages &[]openai.Message- messages(只读借用,调用方仍持有原值;类型 &[]openai.Message)
keep_recent int- keep_recent(int)
返回值
[]openai.Message — 切片结果
format_trace_jsonl
pub fn format_trace_jsonl(spans &[]TraceSpan) string
用途
格式化为 trace jsonl。
参数
spans &[]TraceSpan- spans(只读借用,调用方仍持有原值;类型 &[]TraceSpan)
返回值
string — 结果字符串
run_sequential_workflow
pub fn run_sequential_workflow(agents &[]Agent, names &[]string, initial_prompt string) []WorkflowStepResult
用途
执行 run sequential workflow 操作。失败时抛出错误,调用方需处理或继续传播。
参数
agents &[]Agent- agents(只读借用,调用方仍持有原值;类型 &[]Agent)
names &[]string- names(只读借用,调用方仍持有原值;类型 &[]string)
initial_prompt string- initial_prompt(string)
返回值
[]WorkflowStepResult — 切片结果
run_router_workflow
pub fn run_router_workflow(router &Agent, specialists &[]Agent, specialist_names &[]string, user_prompt string) WorkflowStepResult
用途
执行 run router workflow 操作。失败时抛出错误,调用方需处理或继续传播。
参数
router &Agent- router(只读借用,调用方仍持有原值;类型 &Agent)
specialists &[]Agent- specialists(只读借用,调用方仍持有原值;类型 &[]Agent)
specialist_names &[]string- specialist_names(只读借用,调用方仍持有原值;类型 &[]string)
user_prompt string- user_prompt(string)
返回值
WorkflowStepResult — 该类型的值
(&Session) save_checkpoint_json
pub fn (s &Session) save_checkpoint_json(path string) int
用途
&Session 上的操作:执行 save checkpoint json 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s &Session- 本次调用使用的
Session 实例;以只读借用传入,调用方仍持有实例。
path string- 文件系统路径(string)
返回值
int — 该类型的值
load_session_checkpoint
pub fn load_session_checkpoint(agent Agent, path string) Session
用途
执行 load session checkpoint 操作。失败时抛出错误,调用方需处理或继续传播。
参数
agent Agent- agent(Agent)
path string- 文件系统路径(string)
返回值
Session — 该类型的值
(&Session) save_checkpoint_sqlite
pub fn (s &Session) save_checkpoint_sqlite(path string, session_id string) int
用途
&Session 上的操作:执行 save checkpoint sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
s &Session- 本次调用使用的
Session 实例;以只读借用传入,调用方仍持有实例。
path string- 文件系统路径(string)
session_id string- session_id(string)
返回值
int — 该类型的值
load_session_checkpoint_sqlite
pub fn load_session_checkpoint_sqlite(agent Agent, path string, session_id string) Session
用途
执行 load session checkpoint sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
agent Agent- agent(Agent)
path string- 文件系统路径(string)
session_id string- session_id(string)
返回值
Session — 该类型的值
run_parallel_workflow
pub fn run_parallel_workflow(agents &[]Agent, names &[]string, prompts &[]string) []WorkflowStepResult
用途
执行 run parallel workflow 操作。失败时抛出错误,调用方需处理或继续传播。
参数
agents &[]Agent- agents(只读借用,调用方仍持有原值;类型 &[]Agent)
names &[]string- names(只读借用,调用方仍持有原值;类型 &[]string)
prompts &[]string- prompts(只读借用,调用方仍持有原值;类型 &[]string)
返回值
[]WorkflowStepResult — 切片结果
struct EvalOptResult
pub struct EvalOptResult {
pub content string
pub passed bool
pub rounds int
pub last_feedback string
pub history []WorkflowStepResult
}
用途
承载 content、passed、rounds、last_feedback、history 等属性的结构体。
公开字段
content string- 字段(string)
passed bool- 字段(bool)
rounds int- 字段(int)
last_feedback string- 字段(string)
history []WorkflowStepResult- 字段([]WorkflowStepResult)
run_evaluator_optimizer
pub fn run_evaluator_optimizer(generator &Agent, evaluator &Agent, task string, max_rounds int, pass_marker string) EvalOptResult
用途
执行 run evaluator optimizer 操作。失败时抛出错误,调用方需处理或继续传播。
参数
generator &Agent- generator(只读借用,调用方仍持有原值;类型 &Agent)
evaluator &Agent- evaluator(只读借用,调用方仍持有原值;类型 &Agent)
task string- task(string)
max_rounds int- max_rounds(int)
pass_marker string- pass_marker(string)
返回值
EvalOptResult — 该类型的值
(&Agent) run_json_checked
pub fn (a &Agent) run_json_checked(user_prompt string, required_keys &[]string, max_retries int) RunResult
用途
&Agent 上的操作:执行 run json checked 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a &Agent- 本次调用使用的
Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
required_keys &[]string- required_keys(只读借用,调用方仍持有原值;类型 &[]string)
max_retries int- max_retries(int)
返回值
RunResult — 该类型的值
discover_skills_dir
pub fn discover_skills_dir(dir_path string) []Skill
用途
执行 discover skills dir 操作。失败时抛出错误,调用方需处理或继续传播。
参数
dir_path string- dir_path(string)
返回值
[]Skill — 切片结果
($&Agent) load_skills_dir
pub fn (a $&Agent) load_skills_dir(dir_path string) int
用途
$&Agent 上的操作:执行 load skills dir 操作。失败时抛出错误,调用方需处理或继续传播。
参数
a $&Agent- 本次调用使用的
Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dir_path string- dir_path(string)
返回值
int — 该类型的值
struct GraphNode
pub struct GraphNode {
pub name string
pub handler fn(&string) string
}
用途
承载 name、handler 等属性的结构体。
公开字段
name string- 名字
handler fn(&string) string- 字段(函数值;类型 fn(&string) string)
struct GraphEdge
pub struct GraphEdge {
pub from string
pub to string
}
用途
承载 from、to 等属性的结构体。
公开字段
from string- 字段(string)
to string- 字段(string)
struct GraphCondEdge
pub struct GraphCondEdge {
pub from string
pub router fn(&string) string
}
用途
承载 from、router 等属性的结构体。
公开字段
from string- 字段(string)
router fn(&string) string- 字段(函数值;类型 fn(&string) string)
struct GraphParallelBranch
pub struct GraphParallelBranch {
pub name string
pub handler fn(&string) string
}
用途
承载 name、handler 等属性的结构体。
公开字段
name string- 名字
handler fn(&string) string- 字段(函数值;类型 fn(&string) string)
struct GraphFanOutNode
pub struct GraphFanOutNode {
pub name string
pub branches []GraphParallelBranch
pub reducer fn(&string, &[]string) string
}
用途
承载 name、branches、reducer 等属性的结构体。
公开字段
name string- 名字
branches []GraphParallelBranch- 字段([]GraphParallelBranch)
reducer fn(&string, &[]string) string- 字段(函数值;类型 fn(&string, &[]string) string)
struct StateGraph
pub struct StateGraph {
pub entry string
}
用途
承载 entry 等属性的结构体。
公开字段
entry string- 字段(string)
struct GraphStep
pub struct GraphStep {
pub step int
pub node string
pub input string
pub output string
}
用途
承载 step、node、input、output 等属性的结构体。
公开字段
step int- 字段(int)
node string- 字段(string)
input string- 字段(string)
output string- 字段(string)
struct GraphRunResult
pub struct GraphRunResult {
pub final_state string
pub steps []GraphStep
pub finished bool
pub last_node string
pub interrupted bool
pub next_node string
}
用途
承载 final_state、steps、finished、last_node、interrupted 等属性的结构体。
公开字段
final_state string- 字段(string)
steps []GraphStep- 字段([]GraphStep)
finished bool- 字段(bool)
last_node string- 字段(string)
interrupted bool- 字段(bool)
next_node string- 字段(string)
struct GraphCheckpoint
pub struct GraphCheckpoint {
pub next_node string
pub state string
pub last_node string
pub steps []GraphStep
}
用途
承载 next_node、state、last_node、steps 等属性的结构体。
公开字段
next_node string- 字段(string)
state string- 字段(string)
last_node string- 字段(string)
steps []GraphStep- 字段([]GraphStep)
new_state_graph
pub fn new_state_graph(entry string) StateGraph
用途
构造 state graph。
参数
entry string- entry(string)
返回值
StateGraph — 该类型的值
($&StateGraph) add_interrupt_before
pub fn (g $&StateGraph) add_interrupt_before(node string)
用途
$&StateGraph 上的操作:执行 add interrupt before 操作。
参数
g $&StateGraph- 本次调用使用的
StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
node string- node(string)
返回值
不返回值。
($&StateGraph) add_node
pub fn (g $&StateGraph) add_node(name string, handler fn(&string) string)
用途
$&StateGraph 上的操作:执行 add node 操作。
参数
g $&StateGraph- 本次调用使用的
StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
handler fn(&string) string- handler(函数值;类型 fn(&string) string)
返回值
不返回值。
($&StateGraph) add_parallel_node
pub fn (g $&StateGraph) add_parallel_node(name string, branch_names []string, branch_handlers []fn(&string) string, reducer fn(&string, &[]string) string)
用途
$&StateGraph 上的操作:执行 add parallel node 操作。
参数
g $&StateGraph- 本次调用使用的
StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
branch_names []string- branch_names([]string)
branch_handlers []fn(&string) string- branch_handlers([]fn(&string) string)
reducer fn(&string, &[]string) string- reducer(函数值;类型 fn(&string, &[]string) string)
返回值
不返回值。
($&StateGraph) add_edge
pub fn (g $&StateGraph) add_edge(from string, to string)
用途
$&StateGraph 上的操作:执行 add edge 操作。
参数
g $&StateGraph- 本次调用使用的
StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
from string- from(string)
to string- to(string)
返回值
不返回值。
($&StateGraph) add_conditional_edge
pub fn (g $&StateGraph) add_conditional_edge(from string, router fn(&string) string)
用途
$&StateGraph 上的操作:执行 add conditional edge 操作。
参数
g $&StateGraph- 本次调用使用的
StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
from string- from(string)
router fn(&string) string- router(函数值;类型 fn(&string) string)
返回值
不返回值。
graph_state_get
pub fn graph_state_get(state_json &string, key string, def string) string
用途
执行 graph state get 操作。
参数
state_json &string- state_json(只读借用,调用方仍持有原值;类型 &string)
key string- 键(string)
def string- 默认值(string)
返回值
string — 结果字符串
graph_state_set
pub fn graph_state_set(state_json &string, key string, value string) string
用途
执行 graph state set 操作。
参数
state_json &string- state_json(只读借用,调用方仍持有原值;类型 &string)
key string- 键(string)
value string- value(string)
返回值
string — 结果字符串
(&StateGraph) run
pub fn (g &StateGraph) run(initial_state string, max_steps int) GraphRunResult
用途
&StateGraph 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
g &StateGraph- 本次调用使用的
StateGraph 实例;以只读借用传入,调用方仍持有实例。
initial_state string- initial_state(string)
max_steps int- max_steps(int)
返回值
GraphRunResult — 该类型的值
checkpoint_from_result
pub fn checkpoint_from_result(res &GraphRunResult) GraphCheckpoint
用途
执行 checkpoint from result 操作。
参数
res &GraphRunResult- res(只读借用,调用方仍持有原值;类型 &GraphRunResult)
返回值
GraphCheckpoint — 该类型的值
save_graph_checkpoint
pub fn save_graph_checkpoint(ckpt &GraphCheckpoint, path string) int
用途
执行 save graph checkpoint 操作。失败时抛出错误,调用方需处理或继续传播。
参数
ckpt &GraphCheckpoint- ckpt(只读借用,调用方仍持有原值;类型 &GraphCheckpoint)
path string- 文件系统路径(string)
返回值
int — 该类型的值
load_graph_checkpoint
pub fn load_graph_checkpoint(path string) GraphCheckpoint
用途
执行 load graph checkpoint 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
返回值
GraphCheckpoint — 该类型的值
save_graph_checkpoint_sqlite
pub fn save_graph_checkpoint_sqlite(ckpt &GraphCheckpoint, path string, thread_id string) int
用途
执行 save graph checkpoint sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
ckpt &GraphCheckpoint- ckpt(只读借用,调用方仍持有原值;类型 &GraphCheckpoint)
path string- 文件系统路径(string)
thread_id string- thread_id(string)
返回值
int — 该类型的值
load_graph_checkpoint_sqlite
pub fn load_graph_checkpoint_sqlite(path string, thread_id string) GraphCheckpoint
用途
执行 load graph checkpoint sqlite 操作。失败时抛出错误,调用方需处理或继续传播。
参数
path string- 文件系统路径(string)
thread_id string- thread_id(string)
返回值
GraphCheckpoint — 该类型的值
(&StateGraph) resume
pub fn (g &StateGraph) resume(ckpt &GraphCheckpoint, override_state string, max_steps int) GraphRunResult
用途
在 &StateGraph 上执行 resume 操作。失败时抛出错误,调用方需处理或继续传播。
参数
g &StateGraph- 本次调用使用的
StateGraph 实例;以只读借用传入,调用方仍持有实例。
ckpt &GraphCheckpoint- ckpt(只读借用,调用方仍持有原值;类型 &GraphCheckpoint)
override_state string- override_state(string)
max_steps int- max_steps(int)
返回值
GraphRunResult — 该类型的值
format_trace_otlp_json
pub fn format_trace_otlp_json(service_name string, spans &[]TraceSpan) string
用途
格式化为 trace otlp json。
参数
service_name string- service_name(string)
spans &[]TraceSpan- spans(只读借用,调用方仍持有原值;类型 &[]TraceSpan)
返回值
string — 结果字符串
format_trace_prometheus
pub fn format_trace_prometheus(service_name string, spans &[]TraceSpan) string
用途
格式化为 trace prometheus。
参数
service_name string- service_name(string)
spans &[]TraceSpan- spans(只读借用,调用方仍持有原值;类型 &[]TraceSpan)
返回值
string — 结果字符串
export_traces_otlp_http
pub fn export_traces_otlp_http(endpoint string, service_name string, spans &[]TraceSpan) int
用途
执行 export traces otlp http 操作。失败时抛出错误,调用方需处理或继续传播。
参数
endpoint string- endpoint(string)
service_name string- service_name(string)
spans &[]TraceSpan- spans(只读借用,调用方仍持有原值;类型 &[]TraceSpan)
返回值
int — 该类型的值
struct HandoffAgent
pub struct HandoffAgent {
pub name string
pub instructions string
}
用途
承载 name、instructions 等属性的结构体。
公开字段
name string- 名字
instructions string- 字段(string)
struct HandoffTeam
pub struct HandoffTeam {
pub entry string
pub agents []HandoffAgent
}
用途
承载 entry、agents 等属性的结构体。
公开字段
entry string- 字段(string)
agents []HandoffAgent- 字段([]HandoffAgent)
struct HandoffResult
pub struct HandoffResult {
pub final_agent string
pub content string
pub route_trace []string
pub handoffs int
pub turns int
}
用途
承载 final_agent、content、route_trace、handoffs、turns 等属性的结构体。
公开字段
final_agent string- 字段(string)
content string- 字段(string)
route_trace []string- 字段([]string)
handoffs int- 字段(int)
turns int- 字段(int)
new_handoff_team
pub fn new_handoff_team(entry_agent string) HandoffTeam
用途
构造 handoff team。
参数
entry_agent string- entry_agent(string)
返回值
HandoffTeam — 该类型的值
($&HandoffTeam) add_agent
pub fn (t $&HandoffTeam) add_agent(name string, instructions string)
用途
$&HandoffTeam 上的操作:执行 add agent 操作。
参数
t $&HandoffTeam- 本次调用使用的
HandoffTeam 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
instructions string- instructions(string)
返回值
不返回值。
run_handoff_openai
pub fn run_handoff_openai(team &HandoffTeam, client &openai.Client, model string, user_prompt string, max_handoffs int) HandoffResult
用途
执行 run handoff openai 操作。失败时抛出错误,调用方需处理或继续传播。
参数
team &HandoffTeam- team(只读借用,调用方仍持有原值;类型 &HandoffTeam)
client &openai.Client- client(只读借用,调用方仍持有原值;类型 &openai.Client)
model string- model(string)
user_prompt string- user_prompt(string)
max_handoffs int- max_handoffs(int)
返回值
HandoffResult — 该类型的值
discover_a2a_skills_prompt
pub fn discover_a2a_skills_prompt(base_url string) string
用途
执行 discover a2a skills prompt 操作。失败时抛出错误,调用方需处理或继续传播。
参数
base_url string- base_url(string)
返回值
string — 结果字符串
delegate_to_a2a
pub fn delegate_to_a2a(base_url string, auth_token string, task_id string, prompt string) string
用途
执行 delegate to a2a 操作。失败时抛出错误,调用方需处理或继续传播。
参数
base_url string- base_url(string)
auth_token string- auth_token(string)
task_id string- task_id(string)
prompt string- prompt(string)
返回值
string — 结果字符串
struct SwarmMember
pub struct SwarmMember {
pub name string
pub description string
pub provider string
pub agent Agent
pub anthropic_agent AnthropicAgent
pub gemini_agent GeminiAgent
pub responses_agent ResponsesAgent
}
用途
承载 name、description、provider、agent、anthropic_agent 等属性的结构体。
公开字段
name string- 名字
description string- 字段(string)
provider string- 字段(string)
agent Agent- 字段(Agent)
anthropic_agent AnthropicAgent- 字段(AnthropicAgent)
gemini_agent GeminiAgent- 字段(GeminiAgent)
responses_agent ResponsesAgent- 字段(ResponsesAgent)
struct AgentSwarm
pub struct AgentSwarm {
pub entry string
pub members []SwarmMember
}
用途
承载 entry、members 等属性的结构体。
公开字段
entry string- 字段(string)
members []SwarmMember- 字段([]SwarmMember)
struct SwarmResult
pub struct SwarmResult {
pub final_agent string
pub content string
pub route_trace []string
pub handoffs int
pub turns int
pub steps []Step
pub total_tokens int
}
用途
承载 final_agent、content、route_trace、handoffs、turns 等属性的结构体。
公开字段
final_agent string- 字段(string)
content string- 字段(string)
route_trace []string- 字段([]string)
handoffs int- 字段(int)
turns int- 字段(int)
steps []Step- 字段([]Step)
total_tokens int- 字段(int)
new_agent_swarm
pub fn new_agent_swarm(entry string) AgentSwarm
用途
构造 agent swarm。
参数
entry string- entry(string)
返回值
AgentSwarm — 该类型的值
($&AgentSwarm) add_member
pub fn (s $&AgentSwarm) add_member(name string, description string, agent Agent)
用途
$&AgentSwarm 上的操作:执行 add member 操作。
参数
s $&AgentSwarm- 本次调用使用的
AgentSwarm 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
agent Agent- agent(Agent)
返回值
不返回值。
($&AgentSwarm) add_anthropic_member
pub fn (s $&AgentSwarm) add_anthropic_member(name string, description string, agent AnthropicAgent)
用途
$&AgentSwarm 上的操作:执行 add anthropic member 操作。
参数
s $&AgentSwarm- 本次调用使用的
AgentSwarm 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
agent AnthropicAgent- agent(AnthropicAgent)
返回值
不返回值。
($&AgentSwarm) add_gemini_member
pub fn (s $&AgentSwarm) add_gemini_member(name string, description string, agent GeminiAgent)
用途
$&AgentSwarm 上的操作:执行 add gemini member 操作。
参数
s $&AgentSwarm- 本次调用使用的
AgentSwarm 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
agent GeminiAgent- agent(GeminiAgent)
返回值
不返回值。
($&AgentSwarm) add_responses_member
pub fn (s $&AgentSwarm) add_responses_member(name string, description string, agent ResponsesAgent)
用途
$&AgentSwarm 上的操作:执行 add responses member 操作。
参数
s $&AgentSwarm- 本次调用使用的
AgentSwarm 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string- 名字(string)
description string- description(string)
agent ResponsesAgent- agent(ResponsesAgent)
返回值
不返回值。
(&AgentSwarm) run
pub fn (s &AgentSwarm) run(user_prompt string, max_handoffs int) SwarmResult
用途
&AgentSwarm 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
s &AgentSwarm- 本次调用使用的
AgentSwarm 实例;以只读借用传入,调用方仍持有实例。
user_prompt string- user_prompt(string)
max_handoffs int- max_handoffs(int)
返回值
SwarmResult — 该类型的值