Documentation
¶
Overview ¶
Package agent provides the ADK-Go wrapper for Wails desktop applications.
Package agent provides Chat Completions API model adapter for ADK. This is needed because ADK's openaimodel uses OpenAI Responses API (/v1/responses), which is not supported by providers like DeepSeek that only implement the standard Chat Completions API (/v1/chat/completions).
Package agent provides the ADK-Go wrapper for Wails desktop applications.
Index ¶
- Variables
- type AdkRunner
- type AdkRunnerConfig
- type AgentErrorState
- type AgentErrorType
- type ApprovalResult
- type ChatModel
- func (m *ChatModel) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]
- func (m *ChatModel) Name() string
- func (m *ChatModel) SetThinkingMode(mode string)
- func (m *ChatModel) SimpleChat(ctx context.Context, systemPrompt, userMessage string) (string, error)
- type OrchestratorCallbacks
- type OrchestratorConfig
- type PendingCall
- type QuestionItem
- type QuestionnaireAnswer
- type WailsAgent
- func (w *WailsAgent) BuildAndRun(ctx context.Context, userID, sessionID, message string, ...) error
- func (w *WailsAgent) ResolveApproval(approvalID string, approved bool)
- func (w *WailsAgent) ResolveQuestionnaire(questionnaireID string, answer string)
- func (w *WailsAgent) SetInstruction(instruction string)
- func (w *WailsAgent) SetModel(_ context.Context, apiKey, baseURL, modelName string) error
- func (w *WailsAgent) SetResponsesModel(ctx context.Context, apiKey, baseURL, modelName string) error
- func (w *WailsAgent) SetSubApprovalCallback(cb func(approvalID, command string, riskLevel ftool.RiskLevel))
- func (w *WailsAgent) SetThinking(mode string)
- func (w *WailsAgent) SetTools(tools []tool.Tool)
- type WailsAgentConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultUseChatAPI = true
DefaultUseChatAPI 控制是否默认使用 Chat Completions API 而非 Responses API。 设为 true 时,SetModel 会自动切换到 ChatModel 适配器。
Functions ¶
This section is empty.
Types ¶
type AdkRunner ¶ added in v0.2.0
type AdkRunner struct {
// contains filtered or unexported fields
}
AdkRunner 封装 ADK-Go Runner,将 Event 流转换为 OrchestratorCallbacks。
func NewAdkRunner ¶ added in v0.2.0
func NewAdkRunner(cfg AdkRunnerConfig) (*AdkRunner, error)
NewAdkRunner 创建 AdkRunner。
type AdkRunnerConfig ¶ added in v0.2.0
type AdkRunnerConfig struct {
// AppName 应用名称,用于 session/memory 隔离。
AppName string
// Agent ADK Agent 实例(由调用方通过 llmagent.New 等创建)。
Agent agent.Agent
// SessionService 会话持久化服务。
SessionService session.Service
// MemoryService 记忆服务(可选)。
MemoryService any
// MaxIterations 最大迭代次数限制(0 表示不限制)。
MaxIterations int
}
AdkRunnerConfig 配置 ADK Runner 的参数。
type AgentErrorState ¶
type AgentErrorState struct {
ErrType AgentErrorType
File string
Message string
Retries int
LastAttempt string
}
AgentErrorState 错误状态
type AgentErrorType ¶
type AgentErrorType string
AgentErrorType 错误类型
const ( AgentErrNone AgentErrorType = "" AgentErrCompileFail AgentErrorType = "compile_fail" AgentErrToolFail AgentErrorType = "tool_fail" )
type ApprovalResult ¶
ApprovalResult 审批结果
type ChatModel ¶ added in v0.2.0
type ChatModel struct {
// contains filtered or unexported fields
}
ChatModel implements model.LLM using the standard OpenAI Chat Completions API.
func NewChatModel ¶ added in v0.2.0
NewChatModel creates a new ChatModel. baseURL should be the full endpoint URL, e.g. "https://api.deepseek.com/v1/chat/completions"
func (*ChatModel) GenerateContent ¶ added in v0.2.0
func (m *ChatModel) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]
GenerateContent implements model.LLM.
func (*ChatModel) SetThinkingMode ¶ added in v0.2.0
SetThinkingMode 设置思考模式。 "off" → 不启用思考,其他值 → thinking.type=enabled + reasoning_effort 对应
type OrchestratorCallbacks ¶
type OrchestratorCallbacks struct {
OnMessageStart func(msgID string, seq int64, turnID, role string)
OnContentDelta func(msgID, delta string)
OnReasoningDelta func(msgID, delta string)
OnMessageEnd func(msgID string)
OnToolCallStart func(msgID, callID, name string)
OnToolCallDelta func(callID, argsDelta string)
OnToolCallEnd func(callID, name, arguments string)
OnToolExecuting func(callID, name string)
OnToolResult func(callID, toolMsgID string, result *tool.ToolResult)
OnApprovalRequired func(approvalID, callID, command string, risk tool.RiskLevel)
OnQuestionnaire func(questionnaireID, questionsJSON string)
OnTokenUsage func(usage tool.TokenUsageInfo)
OnTurnComplete func(turnID, sessionID string)
OnError func(msgID, code, message string)
OnTerminalOutput func(text string, isStderr bool)
}
OrchestratorCallbacks 编排器 → 流式通信层的回调接口
type OrchestratorConfig ¶
type OrchestratorConfig struct {
IterationsPerBatch int
ContextWindow int
OutputReserve int
WorkspaceID string
MaxErrorRetries int
}
OrchestratorConfig 编排器配置
type PendingCall ¶
PendingCall 待执行的工具调用
type QuestionItem ¶
QuestionItem 单个问题的回答
type QuestionnaireAnswer ¶
type QuestionnaireAnswer struct {
Answers []QuestionItem `json:"answers"`
}
QuestionnaireAnswer 用户对问卷的回答
type WailsAgent ¶ added in v0.2.0
type WailsAgent struct {
// contains filtered or unexported fields
}
WailsAgent Wails 桌面应用的 Agent 外观。 封装 ADK-Go Runner + 审批系统,供 Wails 桌面应用使用。
func NewWailsAgent ¶ added in v0.2.0
func NewWailsAgent(cfg WailsAgentConfig) *WailsAgent
NewWailsAgent 创建 WailsAgent。
func (*WailsAgent) BuildAndRun ¶ added in v0.2.0
func (w *WailsAgent) BuildAndRun( ctx context.Context, userID, sessionID, message string, callbacks *OrchestratorCallbacks, approvalMode ftool.ApprovalMode, ) error
BuildAndRun 构建 ADK Agent 并运行对话。 callbacks 用于接收流式事件。
func (*WailsAgent) ResolveApproval ¶ added in v0.2.0
func (w *WailsAgent) ResolveApproval(approvalID string, approved bool)
ResolveApproval 处理审批结果。
func (*WailsAgent) ResolveQuestionnaire ¶ added in v0.2.0
func (w *WailsAgent) ResolveQuestionnaire(questionnaireID string, answer string)
ResolveQuestionnaire 处理问卷结果。
func (*WailsAgent) SetInstruction ¶ added in v0.2.0
func (w *WailsAgent) SetInstruction(instruction string)
SetInstruction 设置 Agent 的 system instruction。
func (*WailsAgent) SetModel ¶ added in v0.2.0
func (w *WailsAgent) SetModel(_ context.Context, apiKey, baseURL, modelName string) error
SetModel 设置当前使用的 LLM 模型(使用标准 OpenAI Chat Completions API)。 兼容 DeepSeek、Ollama、vLLM 等所有 /v1/chat/completions 兼容的提供商。
func (*WailsAgent) SetResponsesModel ¶ added in v0.2.0
func (w *WailsAgent) SetResponsesModel(ctx context.Context, apiKey, baseURL, modelName string) error
SetResponsesModel 设置使用 OpenAI Responses API 的模型(仅 OpenAI 原生支持)。 大多数第三方提供商(DeepSeek、Ollama 等)不支持 Responses API,请使用 SetModel。
func (*WailsAgent) SetSubApprovalCallback ¶ added in v0.2.0
func (w *WailsAgent) SetSubApprovalCallback(cb func(approvalID, command string, riskLevel ftool.RiskLevel))
SetSubApprovalCallback 设置子 Agent 审批回调(兼容旧接口)。
func (*WailsAgent) SetThinking ¶ added in v0.2.0
func (w *WailsAgent) SetThinking(mode string)
SetThinking 设置思考模式。会在下一次 BuildAndRun 时生效。
func (*WailsAgent) SetTools ¶ added in v0.2.0
func (w *WailsAgent) SetTools(tools []tool.Tool)
SetTools 设置 Agent 可用的工具列表。
type WailsAgentConfig ¶ added in v0.2.0
type WailsAgentConfig struct {
// AppName 应用标识(框架层不感知具体含义,调用方自行编码 workspace_id)。
AppName string
// SessionService 会话持久化服务。
SessionService session.Service
// MemoryService 记忆服务(可选)。
MemoryService any
// MaxIterations 单次编排最大迭代次数。
MaxIterations int
// 审批超时时间。
ApprovalTimeout time.Duration
}
WailsAgentConfig WailsAgent 配置。