Skip to content

Commit bd3d98e

Browse files
committed
added missing doc comments, resolved minor interface inconsistencies, added AgentExtendedCardProducer interface
1 parent 3280481 commit bd3d98e

File tree

7 files changed

+90
-9
lines changed

7 files changed

+90
-9
lines changed

a2a/errors.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,30 @@ package a2a
1717
import "errors"
1818

1919
var (
20+
// ErrTaskNotFound indicates that a task with the provided ID was not found.
2021
ErrTaskNotFound = errors.New("task not found")
2122

23+
// ErrTaskNotCancelable indicates that the task was in a state where it could not be cancelled.
2224
ErrTaskNotCancelable = errors.New("task cannot be canceled")
2325

26+
// ErrPushNotificationNotSupported indicates that the agent does not support push notifications.
2427
ErrPushNotificationNotSupported = errors.New("push notification not supported")
2528

29+
// ErrUnsupportedOperation indicates that the requested operation is not supported by the agent.
2630
ErrUnsupportedOperation = errors.New("this operation is not supported")
2731

32+
// ErrUnsupportedContentType indicates an incompatibility between the requested
33+
// content types and the agent's capabilities.
2834
ErrUnsupportedContentType = errors.New("incompatible content types")
2935

36+
// ErrInvalidAgentResponse indicates that the agent returned a response that
37+
// does not conform to the specification for the current method.
3038
ErrInvalidAgentResponse = errors.New("invalid agent response")
3139

40+
// ErrInvalidRequest indicates that the received request was invalid.
3241
ErrInvalidRequest = errors.New("invalid request")
3342

43+
// ErrAuthenticatedExtendedCardNotConfigured indicates that the agent does not have an Authenticated
44+
// Extended Card configured.
3445
ErrAuthenticatedExtendedCardNotConfigured = errors.New("extended card not configured")
3546
)

a2a/push.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ type GetTaskPushConfigParams struct {
2323
ConfigID *string
2424
}
2525

26-
// Defines parameters for listing all push notification configurations associated
27-
// with a task.
26+
// Defines parameters for listing all push notification configurations associated with a task.
2827
type ListTaskPushConfigParams struct {
2928
// The unique identifier of the task.
3029
TaskID TaskID

a2asrv/agent.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,36 @@ import (
2020
"github.com/a2aproject/a2a-go/a2a"
2121
)
2222

23+
// AgentExecutor implementations translate agent outputs to A2A events.
2324
type AgentExecutor interface {
24-
Execute(ctx context.Context, reqCtx RequestContext, queue EventQueue) error
25+
// Execute invokes an agent with the provided context and translates agent outputs
26+
// into A2A events writing them to the provided event queue.
27+
//
28+
// Returns an error if agent invocation failed.
29+
Execute(ctx context.Context, reqCtx RequestContext, queue EventWriter) error
2530

26-
Cancel(ctx context.Context, reqCtx RequestContext, queue EventQueue) error
31+
// Cancel requests the agent to stop processing an ongoing task.
32+
//
33+
// The agent should attempt to gracefully stop the task identified by the
34+
// task ID in the request context and publish a TaskStatusUpdateEvent with
35+
// state TaskStateCanceled to the event queue.
36+
//
37+
// Returns an error if the cancellation request cannot be processed.
38+
Cancel(ctx context.Context, reqCtx RequestContext, queue EventWriter) error
2739
}
2840

41+
// AgentCardProducer creates an AgentCard instances used for agent discovery and capability negotiation.
2942
type AgentCardProducer interface {
43+
// Card returns a self-describing manifest for an agent. It provides essential
44+
// metadata including the agent's identity, capabilities, skills, supported
45+
// communication methods, and security requirements and is publicly available.
3046
Card() a2a.AgentCard
3147
}
48+
49+
// ExtendedAgentCardProducer can create both public agent cards and cards available to authenticated users only.
50+
type ExtendedAgentCardProducer interface {
51+
AgentCardProducer
52+
53+
// ExtendedCard returns a manifest for an agent which is only available to authenticated users.
54+
ExtendedCard() a2a.AgentCard
55+
}

a2asrv/events.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,37 @@ import (
2020
"github.com/a2aproject/a2a-go/a2a"
2121
)
2222

23+
// EventReader defines the interface for reading events from a queue.
24+
// A2A server stack reads events written by AgentExecutor.
2325
type EventReader interface {
26+
// Read dequeues an event or blocks if the queue is empty.
2427
Read(ctx context.Context) (a2a.Event, error)
2528
}
2629

30+
// EventWriter defines the interface for writing events to a queue.
31+
// AgentExecutor translates agent responses to Messages, Tasks or Task update events.
2732
type EventWriter interface {
33+
// Write enqueues an event or blocks if a bounded queue is full.
2834
Write(ctx context.Context, event a2a.Event) error
2935
}
3036

37+
// EventQueue defines the interface for publishing and consuming
38+
// events generated during agent execution.
3139
type EventQueue interface {
3240
EventReader
3341
EventWriter
3442

43+
// Close shuts down a connection to the queue.
3544
Close()
3645
}
3746

47+
// EventQueueManager manages event queues on a per-task basis.
48+
// It provides lifecycle management for task-specific event queues,
49+
// enabling multiple clients to attach to the same task's event stream.
3850
type EventQueueManager interface {
51+
// GetOrCreate returns an existing queue if one exists, or creates a new one.
3952
GetOrCreate(ctx context.Context, taskId a2a.TaskID) (EventQueue, error)
4053

54+
// Destroy closes the queue for the specified task and frees all associates resources.
4155
Destroy(ctx context.Context, taskId a2a.TaskID) error
4256
}

a2asrv/handler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,32 @@ import (
2121
"github.com/a2aproject/a2a-go/a2a"
2222
)
2323

24+
// RequestHandler defines a transport-agnostic interface for handling incoming A2A requests.
2425
type RequestHandler interface {
26+
// OnGetTask handles the 'tasks/get' protocol method.
2527
OnGetTask(ctx context.Context, query a2a.TaskQueryParams) (a2a.Task, error)
2628

29+
// OnCancelTask handles the 'tasks/cancel' protocol method.
2730
OnCancelTask(ctx context.Context, id a2a.TaskIDParams) (a2a.Task, error)
2831

32+
// OnSendMessage handles the 'message/send' protocol method (non-streaming).
2933
OnSendMessage(ctx context.Context, message a2a.MessageSendParams) (a2a.SendMessageResult, error)
3034

35+
// OnResubscribeToTask handles the `tasks/resubscribe` protocol method.
3136
OnResubscribeToTask(ctx context.Context, id a2a.TaskIDParams) iter.Seq2[a2a.Event, error]
3237

38+
// OnMessageSendStream handles the 'message/stream' protocol method (streaming).
3339
OnSendMessageStream(ctx context.Context, message a2a.MessageSendParams) iter.Seq2[a2a.Event, error]
3440

41+
// OnGetTaskPushNotificationConfig handles the `tasks/pushNotificationConfig/get` protocol method.
3542
OnGetTaskPushConfig(ctx context.Context, params a2a.GetTaskPushConfigParams) (a2a.TaskPushConfig, error)
3643

44+
// OnListTaskPushNotificationConfig handles the `tasks/pushNotificationConfig/list` protocol method.
3745
OnListTaskPushConfig(ctx context.Context, params a2a.ListTaskPushConfigParams) ([]a2a.TaskPushConfig, error)
3846

47+
// OnSetTaskPushConfig handles the `tasks/pushNotificationConfig/set` protocol method.
3948
OnSetTaskPushConfig(ctx context.Context, params a2a.TaskPushConfig) (a2a.TaskPushConfig, error)
4049

50+
// OnDeleteTaskPushNotificationConfig handles the `tasks/pushNotificationConfig/delete` protocol method.
4151
OnDeleteTaskPushConfig(ctx context.Context, params a2a.DeleteTaskPushConfigParams) error
4252
}

a2asrv/reqctx.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ import (
2020
"github.com/a2aproject/a2a-go/a2a"
2121
)
2222

23+
// RequestContextBuilder defines an extension point for constructing request contexts
24+
// that contain the information needed by AgentExecutor implementations to process incoming requests.
2325
type RequestContextBuilder interface {
26+
// Build constructs a RequestContext from the provided parameters.
2427
Build(ctx context.Context, p a2a.MessageSendParams, t *a2a.Task) RequestContext
2528
}
2629

30+
// RequestContext provides information about an incoming A2A request to AgentExecutor.
2731
type RequestContext struct {
28-
Request a2a.MessageSendParams
29-
TaskID a2a.TaskID
30-
Task *a2a.Task
32+
// Request which triggered the execution.
33+
Request a2a.MessageSendParams
34+
// TaskID is an ID of the task or a newly generated UUIDv4 in case Message did not reference any Task.
35+
TaskID a2a.TaskID
36+
// Task is present if request message specified a TaskID.
37+
Task *a2a.Task
38+
// RelatedTasks can be present when Message includes Task references and RequestContextBuilder is configured to load them.
3139
RelatedTasks []a2a.Task
32-
ContextID string
40+
// ContextID is a server-generated identifier for maintaining context across multiple related tasks or interactions. Matches the Task ContextID.
41+
ContextID string
3342
}

a2asrv/tasks.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,34 @@ import (
2020
"github.com/a2aproject/a2a-go/a2a"
2121
)
2222

23+
// PushNotifier defines the interface for sending push notifications
24+
// about task state changes to external endpoints.
2325
type PushNotifier interface {
26+
// SendPush sends a push notification containing the latest task state.
2427
SendPush(ctx context.Context, task a2a.Task) error
2528
}
2629

30+
// PushConfigStore manages push notification configurations for tasks.
2731
type PushConfigStore interface {
32+
// Save creates or updates a push notification configuration for a task.
33+
// PushConfig has an ID and a Task can have multiple associated configurations.
2834
Save(ctx context.Context, taskId a2a.TaskID, config a2a.PushConfig) error
2935

36+
// Get retrieves all registered push configurations for a Task.
3037
Get(ctx context.Context, taskId a2a.TaskID) ([]a2a.PushConfig, error)
3138

32-
Delete(ctx context.Context, taskId a2a.TaskID) error
39+
// Delete removes a push configuration registered for a Task with the given configID.
40+
Delete(ctx context.Context, taskId a2a.TaskID, configID string) error
41+
42+
// DeleteAll removes all registered push configurations of a Task.
43+
DeleteAll(ctx context.Context, taskId a2a.TaskID) error
3344
}
3445

46+
// TaskStore provides storage for A2A tasks.
3547
type TaskStore interface {
48+
// Save stores a task.
3649
Save(ctx context.Context, task a2a.Task) error
3750

51+
// Get retrieves a task by ID.
3852
Get(ctx context.Context, taskId a2a.TaskID) (a2a.Task, error)
3953
}

0 commit comments

Comments
 (0)