Documentation
¶
Index ¶
- Variables
- type A2AClient
- type A2AMessage
- func FromJSON(data []byte) (*A2AMessage, error)
- func NewA2AMessage(msgType A2AMessageType, from, to string, payload any) *A2AMessage
- func NewCancelMessage(from, to string, taskID string) *A2AMessage
- func NewErrorMessage(from, to string, payload any, replyTo string) *A2AMessage
- func NewResultMessage(from, to string, payload any, replyTo string) *A2AMessage
- func NewStatusMessage(from, to string, payload any, replyTo string) *A2AMessage
- func NewTaskMessage(from, to string, payload any) *A2AMessage
- func ParseA2AMessage(data []byte) (*A2AMessage, error)
- func (m *A2AMessage) Clone() *A2AMessage
- func (m *A2AMessage) CreateReply(msgType A2AMessageType, payload any) *A2AMessage
- func (m *A2AMessage) IsCancel() bool
- func (m *A2AMessage) IsError() bool
- func (m *A2AMessage) IsReply() bool
- func (m *A2AMessage) IsResult() bool
- func (m *A2AMessage) IsStatus() bool
- func (m *A2AMessage) IsTask() bool
- func (m *A2AMessage) MarshalJSON() ([]byte, error)
- func (m *A2AMessage) ToJSON() ([]byte, error)
- func (m *A2AMessage) UnmarshalJSON(data []byte) error
- func (m *A2AMessage) Validate() error
- type A2AMessageType
- type A2AServer
- type AgentCard
- func (c *AgentCard) AddCapability(name, description string, capType CapabilityType) *AgentCard
- func (c *AgentCard) AddTool(name, description string, parameters *structured.JSONSchema) *AgentCard
- func (c *AgentCard) GetCapability(name string) *Capability
- func (c *AgentCard) GetMetadata(key string) (string, bool)
- func (c *AgentCard) GetTool(name string) *ToolDefinition
- func (c *AgentCard) HasCapability(name string) bool
- func (c *AgentCard) HasTool(name string) bool
- func (c *AgentCard) SetInputSchema(schema *structured.JSONSchema) *AgentCard
- func (c *AgentCard) SetMetadata(key, value string) *AgentCard
- func (c *AgentCard) SetOutputSchema(schema *structured.JSONSchema) *AgentCard
- func (c *AgentCard) Validate() error
- type AgentCardGenerator
- type AgentConfigProvider
- type AgentType
- type AsyncResponse
- type Capability
- type CapabilityType
- type ClientConfig
- type HTTPClient
- func (c *HTTPClient) CleanupExpiredTasks(maxAge time.Duration) int
- func (c *HTTPClient) ClearCache()
- func (c *HTTPClient) ClearTaskRegistry()
- func (c *HTTPClient) Discover(ctx context.Context, url string) (*AgentCard, error)
- func (c *HTTPClient) GetResult(ctx context.Context, taskID string) (*A2AMessage, error)
- func (c *HTTPClient) GetResultFromAgent(ctx context.Context, agentURL, taskID string) (*A2AMessage, error)
- func (c *HTTPClient) RegisterTask(taskID, agentURL string)
- func (c *HTTPClient) Send(ctx context.Context, msg *A2AMessage) (*A2AMessage, error)
- func (c *HTTPClient) SendAsync(ctx context.Context, msg *A2AMessage) (string, error)
- func (c *HTTPClient) SetHeader(key, value string)
- func (c *HTTPClient) SetTimeout(timeout time.Duration)
- func (c *HTTPClient) UnregisterTask(taskID string)
- type HTTPServer
- func (s *HTTPServer) AgentCount() int
- func (s *HTTPServer) CancelTask(taskID string) error
- func (s *HTTPServer) CleanupExpiredTasks(maxAge time.Duration) int
- func (s *HTTPServer) GetAgentCard(agentID string) (*AgentCard, error)
- func (s *HTTPServer) GetTaskStatus(taskID string) (string, error)
- func (s *HTTPServer) ListAgents() []string
- func (s *HTTPServer) RecoverTasks(ctx context.Context) error
- func (s *HTTPServer) RegisterAgent(ag agent.Agent) error
- func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) SetTaskStore(store persistence.TaskStore)
- func (s *HTTPServer) StartCleanupLoop(ctx context.Context, interval time.Duration, maxAge time.Duration)
- func (s *HTTPServer) TaskStats(ctx context.Context) (*persistence.TaskStoreStats, error)
- func (s *HTTPServer) UnregisterAgent(agentID string) error
- type ServerConfig
- type SimpleAgentConfig
- type ToolDefinition
- type ToolSchemaProvider
Constants ¶
This section is empty.
Variables ¶
var ( // 错失 名称表示代理卡缺少一个名称. ErrMissingName = errors.New("agent card: missing name") // ErrMissing Description 显示代理卡缺少描述 。 ErrMissingDescription = errors.New("agent card: missing description") // ErrMissingURL 显示代理卡缺少一个 URL 。 ErrMissingURL = errors.New("agent card: missing url") // ErrMissingVersion表示代理卡缺少一个版本. ErrMissingVersion = errors.New("agent card: missing version") )
代理卡验证错误.
var ( // ErrAgentNotFound表示未找到被请求的代理人. ErrAgentNotFound = errors.New("a2a: agent not found") ErrRemoteUnavailable = errors.New("a2a: remote agent unavailable") // ErrAuth 失败表示认证失败 。 ErrAuthFailed = errors.New("a2a: authentication failed") // ErrInvalidMessage 表示信件格式无效 。 ErrInvalidMessage = errors.New("a2a: invalid message format") )
A2A 协议错误 。
var ( // ErrMessage MissingID 显示消息缺少一个ID. ErrMessageMissingID = errors.New("a2a message: missing id") // ErrMessage InvalidType 表示消息类型无效 。 ErrMessageInvalidType = errors.New("a2a message: invalid type") // 误差 显示信件缺少发送者 。 ErrMessageMissingFrom = errors.New("a2a message: missing from") // ErrMessage Missing To 表示信件缺少收件人 。 ErrMessageMissingTo = errors.New("a2a message: missing to") // ErrMessage Missing Timestamp 显示消息缺少一个时间戳 。 ErrMessageMissingTimestamp = errors.New("a2a message: missing timestamp") )
A2A 信件验证错误 。
var ( // ErrTask NotReady 表示正在处理同步任务 。 ErrTaskNotReady = errors.New("a2a: task not ready") // ErrTaskNotFound 表示未找到任务 。 ErrTaskNotFound = errors.New("a2a: task not found") )
A2A客户端出错.
Functions ¶
This section is empty.
Types ¶
type A2AClient ¶
type A2AClient interface {
// 发现从远程特工处取回特工卡
Discover(ctx context.Context, url string) (*AgentCard, error)
// 发送消息同步并等待回复.
Send(ctx context.Context, msg *A2AMessage) (*A2AMessage, error)
// SendAsync 同步发送消息并返回任务ID.
SendAsync(ctx context.Context, msg *A2AMessage) (string, error)
// GetResult通过任务ID检索一个同步任务的结果.
GetResult(ctx context.Context, taskID string) (*A2AMessage, error)
}
A2AClient定义了A2A客户端操作的接口.
type A2AMessage ¶
type A2AMessage struct {
// ID是此消息的唯一标识符 。
ID string `json:"id"`
// 类型表示信件类型(任务,结果,出错,状态,取消).
Type A2AMessageType `json:"type"`
// 从是发件人的标识符.
From string `json:"from"`
// 为接收代理的识别符.
To string `json:"to"`
// 有效载荷包含消息数据.
Payload any `json:"payload"`
// 时间戳是消息创建时.
Timestamp time.Time `json:"timestamp"`
// PresidentTo 是此回复信件的ID( 可选) 。
ReplyTo string `json:"reply_to,omitempty"`
}
A2AMessage代表了代理对代理通信的A2A标准消息.
func NewA2AMessage ¶
func NewA2AMessage(msgType A2AMessageType, from, to string, payload any) *A2AMessage
新建A2 AMessage创建了一个新的A2AMessage,并带有生成的ID和当前时间戳.
func NewCancelMessage ¶
func NewCancelMessage(from, to string, taskID string) *A2AMessage
NewCancelMessage创建了新的取消消息.
func NewErrorMessage ¶
func NewErrorMessage(from, to string, payload any, replyTo string) *A2AMessage
NewErrorMessage 创建新错误消息以响应任务 。
func NewResultMessage ¶
func NewResultMessage(from, to string, payload any, replyTo string) *A2AMessage
NewResultMessage在回复任务时创建了一个新的结果信息.
func NewStatusMessage ¶
func NewStatusMessage(from, to string, payload any, replyTo string) *A2AMessage
新状态消息创建新状态更新消息 。
func NewTaskMessage ¶
func NewTaskMessage(from, to string, payload any) *A2AMessage
NewTaskMessage 创建了新任务请求消息.
func ParseA2AMessage ¶
func ParseA2AMessage(data []byte) (*A2AMessage, error)
ParseA2AMessage将JSON数据分解为A2AMessage并验证.
func (*A2AMessage) CreateReply ¶
func (m *A2AMessage) CreateReply(msgType A2AMessageType, payload any) *A2AMessage
CreatReply 创建此信件的回覆信件 。
func (*A2AMessage) MarshalJSON ¶
func (m *A2AMessage) MarshalJSON() ([]byte, error)
JSON警长执行JSON。 A2AMessage的元帅
func (*A2AMessage) UnmarshalJSON ¶
func (m *A2AMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON 执行json。 A2AMessage的解马沙勒.
type A2AMessageType ¶
type A2AMessageType string
A2AMessageType代表A2A消息的类型.
const ( // A2AMessage TypeTask 表示任务请求消息 。 A2AMessageTypeTask A2AMessageType = "task" // A2AMessageTypeResult表示任务结果消息. A2AMessageTypeResult A2AMessageType = "result" // A2AMessage TypeError 表示错误消息 。 A2AMessageTypeError A2AMessageType = "error" // A2AMessage Type Status 表示状态更新消息. A2AMessageTypeStatus A2AMessageType = "status" // A2AMessage TypeCancel 表示任务取消消息. A2AMessageTypeCancel A2AMessageType = "cancel" )
func (A2AMessageType) IsValid ¶
func (t A2AMessageType) IsValid() bool
IsValid 检查信件类型是否为有效的 A2A 信件类型 。
type A2AServer ¶
type A2AServer interface {
// 注册代理在服务器上注册本地代理 。
RegisterAgent(agent agent.Agent) error
// Unregister Agent 从服务器中删除一个代理 。
UnregisterAgent(agentID string) error
// ServiHTTP 执行 http. 服务A2A请求的掌上电脑
ServeHTTP(w http.ResponseWriter, r *http.Request)
// Get AgentCard为注册代理人取回代理卡.
GetAgentCard(agentID string) (*AgentCard, error)
}
A2AServer定义了A2A服务器操作的接口.
type AgentCard ¶
type AgentCard struct {
// 名称是此代理的唯一标识符 。
Name string `json:"name"`
// 描述提供了一种人能读取的关于该剂目的的描述.
Description string `json:"description"`
// URL是能够到达此代理的终点 。
URL string `json:"url"`
// 版本表示代理的版本.
Version string `json:"version"`
// 能力列出这个代理提供的能力.
Capabilities []Capability `json:"capabilities"`
// 输入Schema定义了代理商的预期输入格式的JSON Schema.
InputSchema *structured.JSONSchema `json:"input_schema,omitempty"`
// OutsionSchema定义了代理输出格式的JSON Schema.
OutputSchema *structured.JSONSchema `json:"output_schema,omitempty"`
// 工具列出这个代理可以使用或曝光的工具.
Tools []ToolDefinition `json:"tools,omitempty"`
// 元数据包含额外的可扩展性的密钥值对.
Metadata map[string]string `json:"metadata,omitempty"`
}
AgentCard代表一个描述代理能力和元数据的A2A代理卡. 它遵循了Google A2A关于特工发现和互操作性的规格.
func NewAgentCard ¶
NewAgentCard创建了具有所需字段的新AgentCard.
func (*AgentCard) AddCapability ¶
func (c *AgentCard) AddCapability(name, description string, capType CapabilityType) *AgentCard
添加能力在代理卡上增加了一个能力.
func (*AgentCard) AddTool ¶
func (c *AgentCard) AddTool(name, description string, parameters *structured.JSONSchema) *AgentCard
AddTool在代理卡上添加了工具定义.
func (*AgentCard) GetCapability ¶
func (c *AgentCard) GetCapability(name string) *Capability
Get Capability 按名称检索一个能力.
func (*AgentCard) GetMetadata ¶
GetMetadata 按键检索元数据值 。
func (*AgentCard) GetTool ¶
func (c *AgentCard) GetTool(name string) *ToolDefinition
GetTool 检索一个工具名称定义 。
func (*AgentCard) HasCapability ¶
如果代理人有特定的能力,则进行能力检查。
func (*AgentCard) SetInputSchema ¶
func (c *AgentCard) SetInputSchema(schema *structured.JSONSchema) *AgentCard
SetInputSchema为代理卡设置输入方案.
func (*AgentCard) SetMetadata ¶
SetMetadata 设置了元数据密钥值对.
func (*AgentCard) SetOutputSchema ¶
func (c *AgentCard) SetOutputSchema(schema *structured.JSONSchema) *AgentCard
SetOutputSchema为代理卡设置输出计划.
type AgentCardGenerator ¶
type AgentCardGenerator struct {
// contains filtered or unexported fields
}
AgentCardGenerator通过代理配置生成代理卡.
func NewAgentCardGenerator ¶
func NewAgentCardGenerator() *AgentCardGenerator
新代理CardGenerator创建了新的代理CardGenerator.
func NewAgentCardGeneratorWithVersion ¶
func NewAgentCardGeneratorWithVersion(version string) *AgentCardGenerator
NewAgentCardGenerator With Version 创建了自定义默认版本的新AgentCardGenerator.
func (*AgentCardGenerator) Generate ¶
func (g *AgentCardGenerator) Generate(config AgentConfigProvider, baseURL string) *AgentCard
从代理配置和基址生成 AgentCard 。 碱基URL应该是能到达剂的终点.
func (*AgentCardGenerator) GenerateWithTools ¶
func (g *AgentCardGenerator) GenerateWithTools(config AgentConfigProvider, baseURL string, toolProvider ToolSchemaProvider) *AgentCard
生成 With Tools 创建了 AgentCard 从 ToolSchema Provider 生成工具定义.
type AgentConfigProvider ¶
type AgentConfigProvider interface {
ID() string
Name() string
Type() AgentType
Description() string
Tools() []string
Metadata() map[string]string
}
Agent Config Provider 定义访问代理配置的接口. 这使得生成器能够配合任何代理执行.
type AsyncResponse ¶
type AsyncResponse struct {
TaskID string `json:"task_id"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
EstimatedTime int `json:"estimated_time,omitempty"` // seconds
}
AsyncResponse代表了从一个Async消息提交中获取的响应.
type Capability ¶
type Capability struct {
// 名称是此能力的唯一标识符 。
Name string `json:"name"`
// 描述为人们提供了这种能力的可读性描述.
Description string `json:"description"`
// 类型表示能力类型(任务,查询,流).
Type CapabilityType `json:"type"`
}
能力在A2A协议中定义了代理的能力.
type CapabilityType ¶
type CapabilityType string
能力 类型代表一种代理人提供的能力类型。
const ( // 能力TypeTask表示代理可以执行任务. CapabilityTypeTask CapabilityType = "task" // 能力 TypeQuery表示代理可以回答询问. CapabilityTypeQuery CapabilityType = "query" // 能力 TypeStream 表示代理支持流响应. CapabilityTypeStream CapabilityType = "stream" )
type ClientConfig ¶
type ClientConfig struct {
// 超时是HTTP请求的默认超时.
Timeout time.Duration
// RetryCount 是失败请求的重试次数 。
RetryCount int
// RetryDelay是重试之间的延迟.
RetryDelay time.Duration
// 信头是请求中要包含的额外信头 。
Headers map[string]string
// AgentID 是本地代理提出请求的标识符 。
AgentID string
}
客户端Config为A2A客户端持有配置.
func DefaultClientConfig ¶
func DefaultClientConfig() *ClientConfig
默认 ClientConfig 返回有合理默认的客户端Config 。
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient是A2AClient使用HTTP的默认执行.
func NewHTTPClient ¶
func NewHTTPClient(config *ClientConfig) *HTTPClient
NewHTTPClient以给定的配置创建了新的HTTPClient.
func (*HTTPClient) CleanupExpiredTasks ¶
func (c *HTTPClient) CleanupExpiredTasks(maxAge time.Duration) int
清理已过期 任务会删除比指定时间长的任务 。
func (*HTTPClient) ClearTaskRegistry ¶
func (c *HTTPClient) ClearTaskRegistry()
ClearTaskRegistry 清除任务注册 。
func (*HTTPClient) Discover ¶
发现从给定的 URL 的远程代理取回 AgentCard 。 URL应该是代理商的基础URL(例如"https://agent.example.com"). 代理卡预计在"/. well-known/agent.json"提供.
func (*HTTPClient) GetResult ¶
func (c *HTTPClient) GetResult(ctx context.Context, taskID string) (*A2AMessage, error)
GetResult通过任务ID检索一个同步任务的结果. 如果任务仍在处理中, 返回 ErrTask NotReady 。 如果任务ID没有注册, 返回 ErrTask NotFound 。
func (*HTTPClient) GetResultFromAgent ¶
func (c *HTTPClient) GetResultFromAgent(ctx context.Context, agentURL, taskID string) (*A2AMessage, error)
GetResultFrom Agent从特定代理中获取了某项协同任务的结果.
func (*HTTPClient) RegisterTask ¶
func (c *HTTPClient) RegisterTask(taskID, agentURL string)
注册任务用代理 URL 手动注册任务ID 。 当任务在 SendAsync 之外创建时, 这一点是有用的 。
func (*HTTPClient) Send ¶
func (c *HTTPClient) Send(ctx context.Context, msg *A2AMessage) (*A2AMessage, error)
发送消息同步并等待回复. 消息发送到消息"to field"中指定的代理.
func (*HTTPClient) SendAsync ¶
func (c *HTTPClient) SendAsync(ctx context.Context, msg *A2AMessage) (string, error)
SendAsync 同步发送消息并返回任务ID. 呼叫者可以使用GetResult对结果进行投票.
func (*HTTPClient) SetHeader ¶
func (c *HTTPClient) SetHeader(key, value string)
Setheader 为所有请求设置自定义标题 。
func (*HTTPClient) SetTimeout ¶
func (c *HTTPClient) SetTimeout(timeout time.Duration)
SetTimeout 设置 HTTP 客户端超时.
func (*HTTPClient) UnregisterTask ¶
func (c *HTTPClient) UnregisterTask(taskID string)
未注册的任务从登记簿中删除 。
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer是A2AServer使用HTTP的默认执行. 支持任务持续在服务重启后恢复 。
func NewHTTPServer ¶
func NewHTTPServer(config *ServerConfig) *HTTPServer
NewHTTPServer用给定的配置创建了新的HTTPServer.
func NewHTTPServerWithTaskStore ¶
func NewHTTPServerWithTaskStore(config *ServerConfig, taskStore persistence.TaskStore) *HTTPServer
NewHTTPServer With TaskStore创建了新的HTTPServer,任务持续.
func (*HTTPServer) CleanupExpiredTasks ¶
func (s *HTTPServer) CleanupExpiredTasks(maxAge time.Duration) int
清理已过期 任务删除超过指定期限的已完成或失败的任务 。
func (*HTTPServer) GetAgentCard ¶
func (s *HTTPServer) GetAgentCard(agentID string) (*AgentCard, error)
Get AgentCard为注册代理人取回代理卡.
func (*HTTPServer) GetTaskStatus ¶
func (s *HTTPServer) GetTaskStatus(taskID string) (string, error)
GetTaskStatus 返回同步任务状态 。
func (*HTTPServer) RecoverTasks ¶
func (s *HTTPServer) RecoverTasks(ctx context.Context) error
RecoverTasks在服务重启后从持续存储中恢复任务.
func (*HTTPServer) RegisterAgent ¶
func (s *HTTPServer) RegisterAgent(ag agent.Agent) error
注册代理在服务器上注册本地代理 。
func (*HTTPServer) ServeHTTP ¶
func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServiHTTP 执行 http. 服务A2A请求的掌上电脑
func (*HTTPServer) SetTaskStore ¶
func (s *HTTPServer) SetTaskStore(store persistence.TaskStore)
SetTaskStore 设置任务存储,用于持久性(依赖性注射).
func (*HTTPServer) StartCleanupLoop ¶
func (s *HTTPServer) StartCleanupLoop(ctx context.Context, interval time.Duration, maxAge time.Duration)
StartCleanupLoop 启动背景goroutine以定期清理已过期的任务 。
func (*HTTPServer) TaskStats ¶
func (s *HTTPServer) TaskStats(ctx context.Context) (*persistence.TaskStoreStats, error)
TaskStats 返回关于任务存储的统计数据 。
func (*HTTPServer) UnregisterAgent ¶
func (s *HTTPServer) UnregisterAgent(agentID string) error
Unregister Agent 从服务器中删除一个代理 。
type ServerConfig ¶
type ServerConfig struct {
// BaseURL 是此服务器可访问的基础 URL 。
BaseURL string
// 默认代理ID是在没有特定代理目标时使用的代理ID.
DefaultAgentID string
// 请求超时是处理请求的超时.
RequestTimeout time.Duration
// 启用 Auth 允许对收到的请求进行认证 。
EnableAuth bool
// AuthToken 是预期的认证符( 如果 EullAuth 是真实的) 。
AuthToken string
// logger 是日志实例 。
Logger *zap.Logger
}
服务器Config持有A2A服务器的配置.
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
默认ServerConfig 返回带有合理默认的服务器Config 。
type SimpleAgentConfig ¶
type SimpleAgentConfig struct {
AgentID string
AgentName string
AgentType AgentType
AgentDescription string
AgentTools []string
AgentMetadata map[string]string
}
SimpleAgentConfig是AgentConfig Provider的简单执行,用于测试和基本使用.
func (*SimpleAgentConfig) Metadata ¶
func (c *SimpleAgentConfig) Metadata() map[string]string
元数据返回代理元数据 。
type ToolDefinition ¶
type ToolDefinition struct {
// 名称是此工具的唯一标识符 。
Name string `json:"name"`
// 描述提供了一种人类可以读取的描述,说明这个工具是做什么的.
Description string `json:"description"`
// 参数定义了该工具的输入参数的JSON Schema.
Parameters *structured.JSONSchema `json:"parameters"`
// Version 是工具的版本标识符.
Version string `json:"version,omitempty"`
}
Tool Definition定义了代理人可以使用或曝光的工具.
type ToolSchemaProvider ¶
type ToolSchemaProvider interface {
GetAllowedTools(agentID string) []llm.ToolSchema
}
ToolSchema Provider为一代理提供了工具计划.