This package contains the data structures for the Agent-to-Agent (A2A) communication protocol.
The models package provides type-safe structures for:
- JSON-RPC 2.0 messages
- Agent metadata and capabilities
- Task management
- Error handling
JSONRPCMessage: Base interface for all JSON-RPC messagesJSONRPCMessageIdentifier: Interface for identifying JSON-RPC messagesJSONRPCRequest: Request object structureJSONRPCResponse: Response object structureJSONRPCError: Error object structure
AgentCard: Agent metadata cardAgentProvider: Provider informationAgentCapabilities: Agent capabilitiesAgentSkill: Agent skill definitionAgentAuthentication: Authentication details
Task: Task representationTaskStatus: Task status informationTaskState: Task state enumerationMessage: Message contentPart: Message part (text, file, data)Artifact: Task output artifact
TaskSendParams: Parameters for sending a taskTaskQueryParams: Parameters for querying a taskTaskIDParams: Parameters for task ID-based operationsPushNotificationConfig: Push notification configuration
package main
import (
"a2a/models"
)
func main() {
// Create a task message
message := models.Message{
Role: "user",
Parts: []models.Part{
{
Type: stringPtr("text"),
Text: stringPtr("Hello, A2A agent!"),
},
},
}
// Create task parameters
params := models.TaskSendParams{
ID: "task-1",
Message: message,
}
// Use the parameters...
}The package defines standard error codes for the A2A protocol:
ErrorCodeParseError: Invalid JSONErrorCodeInvalidRequest: Invalid request formatErrorCodeMethodNotFound: Method not foundErrorCodeInvalidParams: Invalid parametersErrorCodeInternalError: Internal server errorErrorCodeTaskNotFound: Task not foundErrorCodeTaskAlreadyExists: Task already existsErrorCodeTaskInProgress: Task in progressErrorCodeTaskCompleted: Task already completedErrorCodeTaskCanceled: Task already canceledErrorCodeTaskFailed: Task already failedErrorCodeInvalidTaskState: Invalid task state transitionErrorCodeInvalidTaskID: Invalid task IDErrorCodeInvalidMessage: Invalid message formatErrorCodeInvalidPart: Invalid message partErrorCodeInvalidArtifact: Invalid artifact formatErrorCodeInvalidFileContent: Invalid file contentErrorCodeInvalidURI: Invalid URI formatErrorCodeInvalidAuthentication: Invalid authenticationErrorCodeAuthenticationRequired: Authentication requiredErrorCodeAuthenticationFailed: Authentication failedErrorCodeRateLimitExceeded: Rate limit exceededErrorCodeQuotaExceeded: Quota exceededErrorCodeServiceUnavailable: Service unavailableErrorCodeTimeout: Request timeoutErrorCodeConnectionError: Connection errorErrorCodeProtocolError: Protocol errorErrorCodeUnknownError: Unknown error
Run the tests with:
go test ./...The test suite verifies:
- JSON serialization/deserialization
- Type validation
- Error handling
- Task state transitions