XU XUv0.16.0

#github.com/xulang-org/packages/agent

导入方式: 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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub struct AgentMemory {
    pub store rag.MemoryStore
}

用途

承载 store 等属性的结构体。

公开字段

store rag.MemoryStore
字段(rag.MemoryStore)

struct WorkflowStepResult

XuAPI
pub struct WorkflowStepResult {
    pub agent_name string
    pub result RunResult
}

用途

承载 agent_name、result 等属性的结构体。

公开字段

agent_name string
字段(string)
result RunResult
字段(RunResult)

struct Agent

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&Agent) add_skill(skill Skill)

用途

$&Agent 上的操作:执行 add skill 操作。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill
skill(Skill)

返回值

不返回值。

($&Agent) set_context_budget

XuAPI
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

XuAPI
pub fn (a $&Agent) set_progressive_skills(enabled bool)

用途

$&Agent 上的操作:设置 progressive skills。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&Agent) set_guardrails_policy

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&Agent) set_system_prompt(prompt string)

用途

$&Agent 上的操作:设置 system prompt。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string
prompt(string)

返回值

不返回值。

($&Agent) set_max_turns

XuAPI
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

XuAPI
pub fn (a $&Agent) set_temperature(t f64)

用途

$&Agent 上的操作:设置 temperature。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64
t(f64)

返回值

不返回值。

($&Agent) set_max_tokens

XuAPI
pub fn (a $&Agent) set_max_tokens(n int)

用途

$&Agent 上的操作:设置 max tokens。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&Agent) set_max_total_tokens

XuAPI
pub fn (a $&Agent) set_max_total_tokens(n int)

用途

$&Agent 上的操作:设置 max total tokens。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&Agent) set_tool_choice

XuAPI
pub fn (a $&Agent) set_tool_choice(choice string)

用途

$&Agent 上的操作:设置 tool choice。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
choice string
choice(string)

返回值

不返回值。

($&Agent) set_response_format

XuAPI
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

XuAPI
pub fn (a $&Agent) set_parallel_tools(enabled bool)

用途

$&Agent 上的操作:设置 parallel tools。

参数

a $&Agent
本次调用使用的 Agent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&Agent) add_tool

XuAPI
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

XuAPI
pub fn from_mcp_tools(tools &[]mcp.ToolInfo) []openai.ToolDef

用途

从 mcp tools 构造。

参数

tools &[]mcp.ToolInfo
tools(只读借用,调用方仍持有原值;类型 &[]mcp.ToolInfo)

返回值

[]openai.ToolDef — 切片结果

from_mcp_anthropic_tools

XuAPI
pub fn from_mcp_anthropic_tools(tools &[]mcp.ToolInfo) []anthropic.Tool

用途

从 mcp anthropic tools 构造。

参数

tools &[]mcp.ToolInfo
tools(只读借用,调用方仍持有原值;类型 &[]mcp.ToolInfo)

返回值

[]anthropic.Tool — 切片结果

struct Session

XuAPI
pub struct Session {
    pub agent Agent
}

用途

承载 agent 等属性的结构体。

公开字段

agent Agent
字段(Agent)

new_session

XuAPI
pub fn new_session(agent Agent) Session

用途

构造 session。

参数

agent Agent
agent(Agent)

返回值

Session — 该类型的值

($&Session) clear

XuAPI
pub fn (s $&Session) clear()

用途

清空所有已缓冲或存储的数据项与内部状态。

参数

s $&Session
本次调用使用的 Session 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&Session) history

XuAPI
pub fn (s &Session) history() []openai.Message

用途

在 &Session 上执行 history 操作。

参数

s &Session
本次调用使用的 Session 实例;以只读借用传入,调用方仍持有实例。

返回值

[]openai.Message — 切片结果

($&Session) send

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a &Agent) run(user_prompt string) RunResult

用途

&Agent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。

参数

a &Agent
本次调用使用的 Agent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string
user_prompt(string)

返回值

RunResult — 该类型的值

(&Agent) run_with_mcp

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&AnthropicAgent) add_skill(skill Skill)

用途

$&AnthropicAgent 上的操作:执行 add skill 操作。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill
skill(Skill)

返回值

不返回值。

($&AnthropicAgent) load_skills_dir

XuAPI
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

XuAPI
pub fn (a $&AnthropicAgent) set_progressive_skills(enabled bool)

用途

$&AnthropicAgent 上的操作:设置 progressive skills。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&AnthropicAgent) set_context_budget

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&AnthropicAgent) set_system_prompt(prompt string)

用途

$&AnthropicAgent 上的操作:设置 system prompt。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string
prompt(string)

返回值

不返回值。

($&AnthropicAgent) set_max_turns

XuAPI
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

XuAPI
pub fn (a $&AnthropicAgent) set_max_tokens(n int)

用途

$&AnthropicAgent 上的操作:设置 max tokens。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&AnthropicAgent) set_max_total_tokens

XuAPI
pub fn (a $&AnthropicAgent) set_max_total_tokens(n int)

用途

$&AnthropicAgent 上的操作:设置 max total tokens。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&AnthropicAgent) set_temperature

XuAPI
pub fn (a $&AnthropicAgent) set_temperature(t f64)

用途

$&AnthropicAgent 上的操作:设置 temperature。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64
t(f64)

返回值

不返回值。

($&AnthropicAgent) set_thinking_budget

XuAPI
pub fn (a $&AnthropicAgent) set_thinking_budget(tokens int)

用途

$&AnthropicAgent 上的操作:设置 thinking budget。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
tokens int
tokens(int)

返回值

不返回值。

($&AnthropicAgent) set_parallel_tools

XuAPI
pub fn (a $&AnthropicAgent) set_parallel_tools(enabled bool)

用途

$&AnthropicAgent 上的操作:设置 parallel tools。

参数

a $&AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&AnthropicAgent) add_tool

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a &AnthropicAgent) run(user_prompt string) RunResult

用途

&AnthropicAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。

参数

a &AnthropicAgent
本次调用使用的 AnthropicAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string
user_prompt(string)

返回值

RunResult — 该类型的值

(&AnthropicAgent) run_with_mcp

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub struct AnthropicSession {
    pub agent AnthropicAgent
}

用途

承载 agent 等属性的结构体。

公开字段

agent AnthropicAgent
字段(AnthropicAgent)

new_anthropic_session

XuAPI
pub fn new_anthropic_session(agent AnthropicAgent) AnthropicSession

用途

构造 anthropic session。

参数

agent AnthropicAgent
agent(AnthropicAgent)

返回值

AnthropicSession — 该类型的值

($&AnthropicSession) clear

XuAPI
pub fn (s $&AnthropicSession) clear()

用途

清空所有已缓冲或存储的数据项与内部状态。

参数

s $&AnthropicSession
本次调用使用的 AnthropicSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&AnthropicSession) history

XuAPI
pub fn (s &AnthropicSession) history() []anthropic.Message

用途

在 &AnthropicSession 上执行 history 操作。

参数

s &AnthropicSession
本次调用使用的 AnthropicSession 实例;以只读借用传入,调用方仍持有实例。

返回值

[]anthropic.Message — 切片结果

($&AnthropicSession) send

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&GeminiAgent) add_skill(skill Skill)

用途

$&GeminiAgent 上的操作:执行 add skill 操作。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill
skill(Skill)

返回值

不返回值。

($&GeminiAgent) load_skills_dir

XuAPI
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

XuAPI
pub fn (a $&GeminiAgent) set_progressive_skills(enabled bool)

用途

$&GeminiAgent 上的操作:设置 progressive skills。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&GeminiAgent) set_context_budget

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&GeminiAgent) set_system_prompt(prompt string)

用途

$&GeminiAgent 上的操作:设置 system prompt。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
prompt string
prompt(string)

返回值

不返回值。

($&GeminiAgent) set_max_turns

XuAPI
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

XuAPI
pub fn (a $&GeminiAgent) set_max_tokens(n int)

用途

$&GeminiAgent 上的操作:设置 max tokens。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&GeminiAgent) set_max_total_tokens

XuAPI
pub fn (a $&GeminiAgent) set_max_total_tokens(n int)

用途

$&GeminiAgent 上的操作:设置 max total tokens。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&GeminiAgent) set_temperature

XuAPI
pub fn (a $&GeminiAgent) set_temperature(t f64)

用途

$&GeminiAgent 上的操作:设置 temperature。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64
t(f64)

返回值

不返回值。

($&GeminiAgent) set_thinking_budget

XuAPI
pub fn (a $&GeminiAgent) set_thinking_budget(tokens int)

用途

$&GeminiAgent 上的操作:设置 thinking budget。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
tokens int
tokens(int)

返回值

不返回值。

($&GeminiAgent) set_parallel_tools

XuAPI
pub fn (a $&GeminiAgent) set_parallel_tools(enabled bool)

用途

$&GeminiAgent 上的操作:设置 parallel tools。

参数

a $&GeminiAgent
本次调用使用的 GeminiAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&GeminiAgent) add_tool

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a &GeminiAgent) run(user_prompt string) RunResult

用途

&GeminiAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。

参数

a &GeminiAgent
本次调用使用的 GeminiAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string
user_prompt(string)

返回值

RunResult — 该类型的值

(&GeminiAgent) run_with_mcp

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub struct GeminiSession {
    pub agent GeminiAgent
}

用途

承载 agent 等属性的结构体。

公开字段

agent GeminiAgent
字段(GeminiAgent)

new_gemini_session

XuAPI
pub fn new_gemini_session(agent GeminiAgent) GeminiSession

用途

构造 gemini session。

参数

agent GeminiAgent
agent(GeminiAgent)

返回值

GeminiSession — 该类型的值

($&GeminiSession) clear

XuAPI
pub fn (s $&GeminiSession) clear()

用途

清空所有已缓冲或存储的数据项与内部状态。

参数

s $&GeminiSession
本次调用使用的 GeminiSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&GeminiSession) history

XuAPI
pub fn (s &GeminiSession) history() []gemini.Content

用途

在 &GeminiSession 上执行 history 操作。

参数

s &GeminiSession
本次调用使用的 GeminiSession 实例;以只读借用传入,调用方仍持有实例。

返回值

[]gemini.Content — 切片结果

($&GeminiSession) send

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a $&ResponsesAgent) set_instructions(s string)

用途

$&ResponsesAgent 上的操作:设置 instructions。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
s string
源字符串(string)

返回值

不返回值。

($&ResponsesAgent) set_max_turns

XuAPI
pub fn (a $&ResponsesAgent) set_max_turns(n int)

用途

$&ResponsesAgent 上的操作:设置 max turns。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&ResponsesAgent) set_temperature

XuAPI
pub fn (a $&ResponsesAgent) set_temperature(t f64)

用途

$&ResponsesAgent 上的操作:设置 temperature。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t f64
t(f64)

返回值

不返回值。

($&ResponsesAgent) set_max_output_tokens

XuAPI
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

XuAPI
pub fn (a $&ResponsesAgent) set_max_total_tokens(n int)

用途

$&ResponsesAgent 上的操作:设置 max total tokens。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&ResponsesAgent) set_tool_choice

XuAPI
pub fn (a $&ResponsesAgent) set_tool_choice(c string)

用途

$&ResponsesAgent 上的操作:设置 tool choice。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
c string
字节或字符码(string)

返回值

不返回值。

($&ResponsesAgent) set_parallel_tools

XuAPI
pub fn (a $&ResponsesAgent) set_parallel_tools(enabled bool)

用途

$&ResponsesAgent 上的操作:设置 parallel tools。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&ResponsesAgent) set_tool_hook

XuAPI
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

XuAPI
pub fn (a $&ResponsesAgent) add_skill(skill Skill)

用途

$&ResponsesAgent 上的操作:执行 add skill 操作。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
skill Skill
skill(Skill)

返回值

不返回值。

($&ResponsesAgent) load_skills_dir

XuAPI
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

XuAPI
pub fn (a $&ResponsesAgent) set_progressive_skills(enabled bool)

用途

$&ResponsesAgent 上的操作:设置 progressive skills。

参数

a $&ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
enabled bool
enabled(bool)

返回值

不返回值。

($&ResponsesAgent) set_context_budget

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (a &ResponsesAgent) run(user_prompt string) RunResult

用途

&ResponsesAgent 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。

参数

a &ResponsesAgent
本次调用使用的 ResponsesAgent 实例;以只读借用传入,调用方仍持有实例。
user_prompt string
user_prompt(string)

返回值

RunResult — 该类型的值

(&ResponsesAgent) run_with_mcp

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn new_responses_session(agent ResponsesAgent) ResponsesSession

用途

构造 responses session。

参数

agent ResponsesAgent
agent(ResponsesAgent)

返回值

ResponsesSession — 该类型的值

($&ResponsesSession) clear

XuAPI
pub fn (s $&ResponsesSession) clear()

用途

清空所有已缓冲或存储的数据项与内部状态。

参数

s $&ResponsesSession
本次调用使用的 ResponsesSession 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&ResponsesSession) last_response_id

XuAPI
pub fn (s &ResponsesSession) last_response_id() string

用途

&ResponsesSession 上的操作:执行 last response id 操作。

参数

s &ResponsesSession
本次调用使用的 ResponsesSession 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

($&ResponsesSession) send

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn parse_skill_markdown(raw &string, path string) Skill

用途

解析为 skill markdown。

参数

raw &string
raw(只读借用,调用方仍持有原值;类型 &string)
path string
文件系统路径(string)

返回值

Skill — 该类型的值

load_skill_file

XuAPI
pub fn load_skill_file(path string) Skill

用途

执行 load skill file 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

Skill — 该类型的值

format_skills_prompt

XuAPI
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

XuAPI
pub fn format_skills_catalog(skills &[]Skill) string

用途

格式化为 skills catalog。

参数

skills &[]Skill
skills(只读借用,调用方仍持有原值;类型 &[]Skill)

返回值

string — 结果字符串

lookup_skill_body

XuAPI
pub fn lookup_skill_body(skills &[]Skill, name &string) string

用途

执行 lookup skill body 操作。

参数

skills &[]Skill
skills(只读借用,调用方仍持有原值;类型 &[]Skill)
name &string
名字(只读借用,调用方仍持有原值;类型 &string)

返回值

string — 结果字符串

new_memory

XuAPI
pub fn new_memory(dim int) AgentMemory

用途

构造 memory。

参数

dim int
dim(int)

返回值

AgentMemory — 该类型的值

($&AgentMemory) remember

XuAPI
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

XuAPI
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

XuAPI
pub fn (m &AgentMemory) format_memories(hits &[]rag.SearchHit) string

用途

&AgentMemory 上的操作:格式化为 memories。

参数

m &AgentMemory
本次调用使用的 AgentMemory 实例;以只读借用传入,调用方仍持有实例。
hits &[]rag.SearchHit
hits(只读借用,调用方仍持有原值;类型 &[]rag.SearchHit)

返回值

string — 结果字符串

($&AgentMemory) forget

XuAPI
pub fn (m $&AgentMemory) forget(id string) bool

用途

在 $&AgentMemory 上执行 forget 操作。

参数

m $&AgentMemory
本次调用使用的 AgentMemory 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string
id(string)

返回值

bool — 是否成立

($&AgentMemory) update

XuAPI
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

XuAPI
pub fn (m &AgentMemory) save_json(path string) int

用途

&AgentMemory 上的操作:执行 save json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

m &AgentMemory
本次调用使用的 AgentMemory 实例;以只读借用传入,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

load_memory_json

XuAPI
pub fn load_memory_json(path string) AgentMemory

用途

执行 load memory json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

AgentMemory — 该类型的值

(&AgentMemory) save_sqlite

XuAPI
pub fn (m &AgentMemory) save_sqlite(path string) int

用途

&AgentMemory 上的操作:执行 save sqlite 操作。失败时抛出错误,调用方需处理或继续传播。

参数

m &AgentMemory
本次调用使用的 AgentMemory 实例;以只读借用传入,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

load_memory_sqlite

XuAPI
pub fn load_memory_sqlite(path string) AgentMemory

用途

执行 load memory sqlite 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

AgentMemory — 该类型的值

estimate_tokens

XuAPI
pub fn estimate_tokens(text &string) int

用途

执行 estimate tokens 操作。

参数

text &string
文本(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

compact_messages_with

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn format_trace_jsonl(spans &[]TraceSpan) string

用途

格式化为 trace jsonl。

参数

spans &[]TraceSpan
spans(只读借用,调用方仍持有原值;类型 &[]TraceSpan)

返回值

string — 结果字符串

run_sequential_workflow

XuAPI
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

XuAPI
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

XuAPI
pub fn (s &Session) save_checkpoint_json(path string) int

用途

&Session 上的操作:执行 save checkpoint json 操作。失败时抛出错误,调用方需处理或继续传播。

参数

s &Session
本次调用使用的 Session 实例;以只读借用传入,调用方仍持有实例。
path string
文件系统路径(string)

返回值

int — 该类型的值

load_session_checkpoint

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn discover_skills_dir(dir_path string) []Skill

用途

执行 discover skills dir 操作。失败时抛出错误,调用方需处理或继续传播。

参数

dir_path string
dir_path(string)

返回值

[]Skill — 切片结果

($&Agent) load_skills_dir

XuAPI
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

XuAPI
pub struct GraphNode {
    pub name string
    pub handler fn(&string) string
}

用途

承载 name、handler 等属性的结构体。

公开字段

name string
名字
handler fn(&string) string
字段(函数值;类型 fn(&string) string)

struct GraphEdge

XuAPI
pub struct GraphEdge {
    pub from string
    pub to string
}

用途

承载 from、to 等属性的结构体。

公开字段

from string
字段(string)
to string
字段(string)

struct GraphCondEdge

XuAPI
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

XuAPI
pub struct GraphParallelBranch {
    pub name string
    pub handler fn(&string) string
}

用途

承载 name、handler 等属性的结构体。

公开字段

name string
名字
handler fn(&string) string
字段(函数值;类型 fn(&string) string)

struct GraphFanOutNode

XuAPI
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

XuAPI
pub struct StateGraph {
    pub entry string
}

用途

承载 entry 等属性的结构体。

公开字段

entry string
字段(string)

struct GraphStep

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn new_state_graph(entry string) StateGraph

用途

构造 state graph。

参数

entry string
entry(string)

返回值

StateGraph — 该类型的值

($&StateGraph) add_interrupt_before

XuAPI
pub fn (g $&StateGraph) add_interrupt_before(node string)

用途

$&StateGraph 上的操作:执行 add interrupt before 操作。

参数

g $&StateGraph
本次调用使用的 StateGraph 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
node string
node(string)

返回值

不返回值。

($&StateGraph) add_node

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn checkpoint_from_result(res &GraphRunResult) GraphCheckpoint

用途

执行 checkpoint from result 操作。

参数

res &GraphRunResult
res(只读借用,调用方仍持有原值;类型 &GraphRunResult)

返回值

GraphCheckpoint — 该类型的值

save_graph_checkpoint

XuAPI
pub fn save_graph_checkpoint(ckpt &GraphCheckpoint, path string) int

用途

执行 save graph checkpoint 操作。失败时抛出错误,调用方需处理或继续传播。

参数

ckpt &GraphCheckpoint
ckpt(只读借用,调用方仍持有原值;类型 &GraphCheckpoint)
path string
文件系统路径(string)

返回值

int — 该类型的值

load_graph_checkpoint

XuAPI
pub fn load_graph_checkpoint(path string) GraphCheckpoint

用途

执行 load graph checkpoint 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path string
文件系统路径(string)

返回值

GraphCheckpoint — 该类型的值

save_graph_checkpoint_sqlite

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub struct HandoffAgent {
    pub name string
    pub instructions string
}

用途

承载 name、instructions 等属性的结构体。

公开字段

name string
名字
instructions string
字段(string)

struct HandoffTeam

XuAPI
pub struct HandoffTeam {
    pub entry string
    pub agents []HandoffAgent
}

用途

承载 entry、agents 等属性的结构体。

公开字段

entry string
字段(string)
agents []HandoffAgent
字段([]HandoffAgent)

struct HandoffResult

XuAPI
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

XuAPI
pub fn new_handoff_team(entry_agent string) HandoffTeam

用途

构造 handoff team。

参数

entry_agent string
entry_agent(string)

返回值

HandoffTeam — 该类型的值

($&HandoffTeam) add_agent

XuAPI
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

XuAPI
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

XuAPI
pub fn discover_a2a_skills_prompt(base_url string) string

用途

执行 discover a2a skills prompt 操作。失败时抛出错误,调用方需处理或继续传播。

参数

base_url string
base_url(string)

返回值

string — 结果字符串

delegate_to_a2a

XuAPI
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

XuAPI
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

XuAPI
pub struct AgentSwarm {
    pub entry string
    pub members []SwarmMember
}

用途

承载 entry、members 等属性的结构体。

公开字段

entry string
字段(string)
members []SwarmMember
字段([]SwarmMember)

struct SwarmResult

XuAPI
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

XuAPI
pub fn new_agent_swarm(entry string) AgentSwarm

用途

构造 agent swarm。

参数

entry string
entry(string)

返回值

AgentSwarm — 该类型的值

($&AgentSwarm) add_member

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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 — 该类型的值