Documentation
¶
Overview ¶
Package a2aserver provides a standalone A2A-protocol HTTP server that can be backed by any conversation implementation satisfying the interfaces defined here. It imports only runtime/ and has no dependency on sdk/.
Index ¶
- Variables
- type AgentCardProvider
- type Authenticator
- type Conversation
- type ConversationOpener
- type EventKind
- type InMemoryTaskStore
- func (s *InMemoryTaskStore) AddArtifacts(taskID string, artifacts []a2a.Artifact) error
- func (s *InMemoryTaskStore) Cancel(taskID string) error
- func (s *InMemoryTaskStore) Create(taskID, contextID string) (*a2a.Task, error)
- func (s *InMemoryTaskStore) EvictTerminal(cutoff time.Time) []string
- func (s *InMemoryTaskStore) Get(taskID string) (*a2a.Task, error)
- func (s *InMemoryTaskStore) List(contextID string, limit, offset int) ([]*a2a.Task, error)
- func (s *InMemoryTaskStore) SetState(taskID string, state a2a.TaskState, msg *a2a.Message) error
- type Option
- func WithAuthenticator(auth Authenticator) Option
- func WithCard(card *a2a.AgentCard) Option
- func WithCardProvider(p AgentCardProvider) Option
- func WithConversationTTL(d time.Duration) Option
- func WithIdleTimeout(d time.Duration) Option
- func WithMaxBodySize(n int64) Option
- func WithPort(port int) Option
- func WithReadTimeout(d time.Duration) Option
- func WithTaskStore(store TaskStore) Option
- func WithTaskTTL(d time.Duration) Option
- func WithWriteTimeout(d time.Duration) Option
- type PendingClientToolInfo
- type ResumableConversation
- type SendResult
- type Server
- type StaticCard
- type StreamEvent
- type StreamingConversation
- type TaskStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrTaskNotFound = errors.New("a2a: task not found") ErrTaskAlreadyExists = errors.New("a2a: task already exists") ErrInvalidTransition = errors.New("a2a: invalid state transition") ErrTaskTerminal = errors.New("a2a: task is in a terminal state") )
Task store errors.
Functions ¶
This section is empty.
Types ¶
type AgentCardProvider ¶
AgentCardProvider returns the agent card to serve at /.well-known/agent.json.
type Authenticator ¶
Authenticator validates incoming requests. Return a non-nil error to reject.
type Conversation ¶
type Conversation interface {
Send(ctx context.Context, message any) (SendResult, error)
Close() error
}
Conversation is the non-streaming conversation interface the server uses.
type ConversationOpener ¶
type ConversationOpener func(contextID string) (Conversation, error)
ConversationOpener creates or retrieves a conversation for a given context ID.
type EventKind ¶
type EventKind int
EventKind discriminates the payload of a StreamEvent.
const ( // EventText indicates the event contains text content. EventText EventKind = iota // EventToolCall indicates a tool call (suppressed by the server). EventToolCall // EventMedia indicates the event contains media content. EventMedia // EventDone indicates the stream is complete. EventDone // EventClientTool indicates a client tool request awaiting fulfillment. EventClientTool )
type InMemoryTaskStore ¶
type InMemoryTaskStore struct {
// contains filtered or unexported fields
}
InMemoryTaskStore is a concurrency-safe, in-memory implementation of TaskStore.
func NewInMemoryTaskStore ¶
func NewInMemoryTaskStore() *InMemoryTaskStore
NewInMemoryTaskStore creates a new InMemoryTaskStore.
func (*InMemoryTaskStore) AddArtifacts ¶
func (s *InMemoryTaskStore) AddArtifacts(taskID string, artifacts []a2a.Artifact) error
AddArtifacts appends artifacts to a task.
func (*InMemoryTaskStore) Cancel ¶
func (s *InMemoryTaskStore) Cancel(taskID string) error
Cancel transitions the task to the canceled state from any non-terminal state.
func (*InMemoryTaskStore) Create ¶
func (s *InMemoryTaskStore) Create(taskID, contextID string) (*a2a.Task, error)
Create initializes a new task in the submitted state.
func (*InMemoryTaskStore) EvictTerminal ¶
func (s *InMemoryTaskStore) EvictTerminal(cutoff time.Time) []string
EvictTerminal removes tasks in a terminal state whose last status timestamp is older than cutoff. It returns the IDs of evicted tasks.
func (*InMemoryTaskStore) Get ¶
func (s *InMemoryTaskStore) Get(taskID string) (*a2a.Task, error)
Get retrieves a task by ID.
type Option ¶
type Option func(*Server)
Option configures a Server.
func WithAuthenticator ¶
func WithAuthenticator(auth Authenticator) Option
WithAuthenticator sets an authenticator for incoming requests.
func WithCardProvider ¶
func WithCardProvider(p AgentCardProvider) Option
WithCardProvider sets a dynamic agent card provider.
func WithConversationTTL ¶
WithConversationTTL sets how long idle conversations are retained before automatic eviction. A conversation is considered idle when its last-use timestamp exceeds this duration. Default: 1 hour. Set to 0 to disable.
func WithIdleTimeout ¶
WithIdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled. Default: 120s.
func WithMaxBodySize ¶
WithMaxBodySize sets the maximum allowed request body size in bytes. Default: 10 MB.
func WithReadTimeout ¶
WithReadTimeout sets the maximum duration for reading the entire request. Default: 30s.
func WithTaskStore ¶
WithTaskStore sets a custom task store. Defaults to an in-memory store.
func WithTaskTTL ¶
WithTaskTTL sets how long completed/failed/canceled tasks are retained before automatic eviction. Default: 1 hour. Set to 0 to disable eviction.
func WithWriteTimeout ¶
WithWriteTimeout sets the maximum duration before timing out writes of the response. Default: 60s.
type PendingClientToolInfo ¶ added in v1.3.8
type PendingClientToolInfo struct {
CallID string `json:"call_id"`
ToolName string `json:"tool_name"`
Args map[string]any `json:"args,omitempty"`
ConsentMsg string `json:"consent_message,omitempty"`
}
PendingClientToolInfo describes a client-side tool call awaiting fulfillment.
type ResumableConversation ¶ added in v1.3.8
type ResumableConversation interface {
Conversation
SendToolResult(callID string, result any) error
RejectClientTool(callID string, reason string)
Resume(ctx context.Context) (SendResult, error)
ResumeStream(ctx context.Context) <-chan StreamEvent
}
ResumableConversation extends Conversation with the ability to submit client-side tool results and resume pipeline execution.
type SendResult ¶
type SendResult interface {
// HasPendingTools reports whether there are tools awaiting approval
// (HITL or client-side). When true the task transitions to input_required.
HasPendingTools() bool
// HasPendingClientTools reports whether there are client-side tools
// awaiting fulfillment by the caller.
HasPendingClientTools() bool
// PendingClientTools returns metadata for each pending client tool.
PendingClientTools() []PendingClientToolInfo
// Parts returns the content parts of the response.
Parts() []types.ContentPart
// Text returns the text content of the response as a fallback
// when Parts() is empty.
Text() string
}
SendResult is what the server needs from a completed conversation turn.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server that exposes a Conversation as an A2A-compliant JSON-RPC endpoint.
func NewServer ¶
func NewServer(opener ConversationOpener, opts ...Option) *Server
NewServer creates a new A2A server.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server on the configured port.
type StaticCard ¶
StaticCard is an AgentCardProvider that always returns the same card.
type StreamEvent ¶
type StreamEvent struct {
Kind EventKind
Text string
Media *types.MediaContent
ClientTool *PendingClientToolInfo
Error error
}
StreamEvent is a single event on a streaming channel.
type StreamingConversation ¶
type StreamingConversation interface {
Conversation
Stream(ctx context.Context, message any) <-chan StreamEvent
}
StreamingConversation extends Conversation with streaming support.
type TaskStore ¶
type TaskStore interface {
Create(taskID, contextID string) (*a2a.Task, error)
Get(taskID string) (*a2a.Task, error)
SetState(taskID string, state a2a.TaskState, msg *a2a.Message) error
AddArtifacts(taskID string, artifacts []a2a.Artifact) error
Cancel(taskID string) error
List(contextID string, limit, offset int) ([]*a2a.Task, error)
// EvictTerminal removes tasks in a terminal state whose last status
// timestamp is older than the given cutoff time. It returns the IDs
// of evicted tasks so callers can clean up associated resources.
EvictTerminal(olderThan time.Time) []string
}
TaskStore defines the interface for task persistence and lifecycle management.