Documentation
¶
Overview ¶
Package aghsdk provides the public Go SDK for AGH subprocess extensions.
The SDK lets extension authors register tool-provider handlers as Go functions while the AGH daemon keeps third-party code out of process.
Index ¶
- Constants
- func CanonicalJSON(raw json.RawMessage) ([]byte, error)
- func SchemaDigest(raw json.RawMessage) (string, error)
- func Tool[TInput any](extension *Extension, handler string, options ToolOptions, ...) error
- type AcceptedCapabilities
- type ActionsConfig
- type ArtifactRef
- type CapabilitiesConfig
- type Extension
- func (e *Extension) GetImplementedMethods() []string
- func (e *Extension) GetToolDescriptors() []ExtensionToolRuntimeDescriptor
- func (e *Extension) Handle(method string, handler ExtensionHandler) error
- func (e *Extension) OnReady(callback func(context.Context, *HostAPI, ExtensionSession) error)
- func (e *Extension) Run(ctx context.Context) error
- func (e *Extension) Tool(handler string, options ToolOptions, fn ToolHandlerFunc[json.RawMessage]) error
- type ExtensionContext
- type ExtensionDefinition
- type ExtensionHandler
- type ExtensionProvideToolsResponse
- type ExtensionSession
- type ExtensionToolCallRequest
- type ExtensionToolCallResponse
- type ExtensionToolRuntimeDescriptor
- type HealthCheckResult
- type HostAPI
- type HostAPIMethod
- type InitializeCapabilities
- type InitializeExtension
- type InitializeExtensionInfo
- type InitializeMethods
- type InitializeRequest
- type InitializeResponse
- type InitializeRuntime
- type InitializeSupports
- type JSONRPCErrorObject
- type JSONRPCRequestEnvelope
- type Option
- type RPCError
- func NewCapabilityDeniedError(data map[string]any) *RPCError
- func NewInternalError(reason string) *RPCError
- func NewInvalidParamsError(reason string, data map[string]any) *RPCError
- func NewInvalidRequestError(reason string) *RPCError
- func NewMethodNotFoundError(method string) *RPCError
- func NewNotInitializedError() *RPCError
- func NewRPCError(code int, message string, data any) *RPCError
- func NewShutdownInProgressError(deadlineMS int64) *RPCError
- func NewToolExecutionError(data map[string]any) *RPCError
- type Redaction
- type RiskClass
- type SecurityConfig
- type ShutdownRequest
- type ShutdownResponse
- type StdioTransport
- type StdioTransportOptions
- type ToolContent
- type ToolHandlerFunc
- type ToolID
- type ToolOptions
- type ToolRequest
- type ToolResult
- type Transport
- type TransportHandler
Constants ¶
const CapabilityToolProvider = "tool.provider"
CapabilityToolProvider is the provide surface for executable extension-host tools.
const DefaultMaxMessageBytes = 10 * 1024 * 1024
DefaultMaxMessageBytes is the default JSON-RPC line size limit.
const ExtensionServiceMethodProvideTools = "provide_tools"
ExtensionServiceMethodProvideTools is the runtime descriptor service method.
const ExtensionServiceMethodToolsCall = "tools/call"
ExtensionServiceMethodToolsCall is the tool invocation service method.
const JSONRPCVersion = "2.0"
JSONRPCVersion is the JSON-RPC protocol version used by the subprocess runtime.
const ProtocolVersion = "1"
ProtocolVersion is the AGH extension subprocess protocol version.
const SDKName = "github.com/compozy/agh/sdk/go"
SDKName is advertised during extension initialization.
const SDKVersion = "0.1.0"
SDKVersion is the public SDK protocol implementation version.
Variables ¶
This section is empty.
Functions ¶
func CanonicalJSON ¶
func CanonicalJSON(raw json.RawMessage) ([]byte, error)
CanonicalJSON returns RFC 8785/JCS-compatible canonical JSON bytes.
func SchemaDigest ¶
func SchemaDigest(raw json.RawMessage) (string, error)
SchemaDigest returns the lowercase SHA-256 digest of a canonical JSON Schema subtree.
func Tool ¶
func Tool[TInput any]( extension *Extension, handler string, options ToolOptions, fn ToolHandlerFunc[TInput], ) error
Tool registers a typed Go function as an extension-host tool handler.
Types ¶
type AcceptedCapabilities ¶
type AcceptedCapabilities struct {
Provides []string `json:"provides"`
Actions []HostAPIMethod `json:"actions"`
Security []string `json:"security"`
}
AcceptedCapabilities is the subset the extension accepted for this session.
type ActionsConfig ¶
type ActionsConfig struct {
Requires []HostAPIMethod `json:"requires,omitempty"`
}
ActionsConfig lists required Host API methods.
type ArtifactRef ¶
type ArtifactRef struct {
URI string `json:"uri"`
Name string `json:"name,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
Bytes int64 `json:"bytes,omitempty"`
}
ArtifactRef points to a durable tool output artifact.
type CapabilitiesConfig ¶
type CapabilitiesConfig struct {
Provides []string `json:"provides,omitempty"`
}
CapabilitiesConfig lists extension-provided capability surfaces.
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension is a subprocess-hosted AGH extension runtime.
func NewExtension ¶
func NewExtension(definition ExtensionDefinition, options ...Option) *Extension
NewExtension creates a public Go extension runtime.
func (*Extension) GetImplementedMethods ¶
GetImplementedMethods returns the sorted method list advertised during initialize.
func (*Extension) GetToolDescriptors ¶
func (e *Extension) GetToolDescriptors() []ExtensionToolRuntimeDescriptor
GetToolDescriptors returns runtime descriptors registered by Tool.
func (*Extension) Handle ¶
func (e *Extension) Handle(method string, handler ExtensionHandler) error
Handle registers one custom AGH -> extension service method.
func (*Extension) Tool ¶
func (e *Extension) Tool( handler string, options ToolOptions, fn ToolHandlerFunc[json.RawMessage], ) error
Tool registers a raw JSON tool handler on the extension.
type ExtensionContext ¶
type ExtensionContext struct {
Request JSONRPCRequestEnvelope
RequestID json.RawMessage
Host *HostAPI
Session ExtensionSession
Logf func(format string, args ...any)
}
ExtensionContext is passed to custom service handlers.
type ExtensionDefinition ¶
type ExtensionDefinition struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
MinAGHVersion string `json:"min_agh_version,omitempty"`
Capabilities CapabilitiesConfig `json:"capabilities"`
Actions ActionsConfig `json:"actions"`
Security SecurityConfig `json:"security"`
SupportedHookEvents []string `json:"supported_hook_events,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
ExtensionDefinition describes one extension process implementation.
type ExtensionHandler ¶
type ExtensionHandler func(context.Context, ExtensionContext, json.RawMessage) (any, error)
ExtensionHandler handles one custom AGH -> extension service request.
type ExtensionProvideToolsResponse ¶
type ExtensionProvideToolsResponse struct {
Tools []ExtensionToolRuntimeDescriptor `json:"tools"`
}
ExtensionProvideToolsResponse is returned by provide_tools.
type ExtensionSession ¶
type ExtensionSession struct {
InitializeRequest InitializeRequest
InitializeResponse InitializeResponse
Runtime InitializeRuntime
AcceptedCapabilities AcceptedCapabilities
}
ExtensionSession is the accepted initialization state visible to handlers.
type ExtensionToolCallRequest ¶
type ExtensionToolCallRequest struct {
ToolID ToolID `json:"tool_id"`
Handler string `json:"handler"`
SessionID string `json:"session_id,omitempty"`
Input json.RawMessage `json:"input"`
}
ExtensionToolCallRequest is sent by AGH for tools/call.
type ExtensionToolCallResponse ¶
type ExtensionToolCallResponse struct {
Result ToolResult `json:"result"`
}
ExtensionToolCallResponse wraps a tool result.
type ExtensionToolRuntimeDescriptor ¶
type ExtensionToolRuntimeDescriptor struct {
ID ToolID `json:"id"`
Handler string `json:"handler"`
InputSchemaDigest string `json:"input_schema_digest"`
OutputSchemaDigest string `json:"output_schema_digest,omitempty"`
ReadOnly bool `json:"read_only"`
Risk RiskClass `json:"risk"`
Capabilities []string `json:"capabilities,omitempty"`
}
ExtensionToolRuntimeDescriptor is the runtime proof descriptor returned by provide_tools.
type HealthCheckResult ¶
type HealthCheckResult struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
Details map[string]json.RawMessage `json:"details,omitempty"`
}
HealthCheckResult is returned by health_check handlers.
type HostAPI ¶
type HostAPI struct {
// contains filtered or unexported fields
}
HostAPI is a minimal typed client for extension Host API calls.
func NewHostAPI ¶
NewHostAPI creates a Host API client over a transport.
func (*HostAPI) RawRequest ¶
func (h *HostAPI) RawRequest(ctx context.Context, method HostAPIMethod, params any) (json.RawMessage, error)
RawRequest calls a Host API method and returns the raw JSON response.
type HostAPIMethod ¶
type HostAPIMethod string
HostAPIMethod identifies one extension -> AGH Host API request.
const ( // HostAPIMethodSessionsList lists sessions visible to the extension. HostAPIMethodSessionsList HostAPIMethod = "sessions/list" // HostAPIMethodSessionsCreate creates a session. HostAPIMethodSessionsCreate HostAPIMethod = "sessions/create" // HostAPIMethodSessionsPrompt prompts a session. HostAPIMethodSessionsPrompt HostAPIMethod = "sessions/prompt" // HostAPIMethodSessionsStop stops a session. HostAPIMethodSessionsStop HostAPIMethod = "sessions/stop" // HostAPIMethodSessionsStatus returns session status. HostAPIMethodSessionsStatus HostAPIMethod = "sessions/status" // HostAPIMethodSessionsStatusGet returns authored-context session status. HostAPIMethodSessionsStatusGet HostAPIMethod = "sessions/status/get" // HostAPIMethodSessionsEvents returns session events. HostAPIMethodSessionsEvents HostAPIMethod = "sessions/events" // HostAPIMethodSessionsSoulRefresh refreshes a session's Soul snapshot through managed authoring. HostAPIMethodSessionsSoulRefresh HostAPIMethod = "sessions/soul/refresh" // HostAPIMethodSessionsHealthGet returns metadata-only session health. HostAPIMethodSessionsHealthGet HostAPIMethod = "sessions/health/get" // HostAPIMethodAgentsSoulGet returns a managed Soul read model. HostAPIMethodAgentsSoulGet HostAPIMethod = "agents/soul/get" // HostAPIMethodAgentsSoulValidate validates Soul content through the managed service. HostAPIMethodAgentsSoulValidate HostAPIMethod = "agents/soul/validate" // HostAPIMethodAgentsSoulPut writes SOUL.md through managed authoring. HostAPIMethodAgentsSoulPut HostAPIMethod = "agents/soul/put" // HostAPIMethodAgentsSoulDelete deletes SOUL.md through managed authoring. HostAPIMethodAgentsSoulDelete HostAPIMethod = "agents/soul/delete" // HostAPIMethodAgentsSoulHistory lists managed Soul authoring revisions. HostAPIMethodAgentsSoulHistory HostAPIMethod = "agents/soul/history" // HostAPIMethodAgentsSoulRollback rolls SOUL.md back through managed authoring. HostAPIMethodAgentsSoulRollback HostAPIMethod = "agents/soul/rollback" // HostAPIMethodAgentsHeartbeatGet returns a managed Heartbeat policy read model. HostAPIMethodAgentsHeartbeatGet HostAPIMethod = "agents/heartbeat/get" // HostAPIMethodAgentsHeartbeatValidate validates Heartbeat content through the managed service. HostAPIMethodAgentsHeartbeatValidate HostAPIMethod = "agents/heartbeat/validate" // HostAPIMethodAgentsHeartbeatPut writes HEARTBEAT.md through managed authoring. HostAPIMethodAgentsHeartbeatPut HostAPIMethod = "agents/heartbeat/put" // HostAPIMethodAgentsHeartbeatDelete deletes HEARTBEAT.md through managed authoring. HostAPIMethodAgentsHeartbeatDelete HostAPIMethod = "agents/heartbeat/delete" // HostAPIMethodAgentsHeartbeatHistory lists managed Heartbeat authoring revisions. HostAPIMethodAgentsHeartbeatHistory HostAPIMethod = "agents/heartbeat/history" // HostAPIMethodAgentsHeartbeatRollback rolls HEARTBEAT.md back through managed authoring. HostAPIMethodAgentsHeartbeatRollback HostAPIMethod = "agents/heartbeat/rollback" // HostAPIMethodAgentsHeartbeatStatus returns policy, session health, and wake audit status. HostAPIMethodAgentsHeartbeatStatus HostAPIMethod = "agents/heartbeat/status" // HostAPIMethodAgentsHeartbeatWake requests one managed advisory Heartbeat wake. HostAPIMethodAgentsHeartbeatWake HostAPIMethod = "agents/heartbeat/wake" // HostAPIMethodMemoryRecall recalls memory. HostAPIMethodMemoryRecall HostAPIMethod = "memory/recall" // HostAPIMethodMemoryStore stores memory. HostAPIMethodMemoryStore HostAPIMethod = "memory/store" // HostAPIMethodMemoryForget forgets memory. HostAPIMethodMemoryForget HostAPIMethod = "memory/forget" // HostAPIMethodObserveHealth returns daemon health. HostAPIMethodObserveHealth HostAPIMethod = "observe/health" // HostAPIMethodListLogs returns runtime logs. HostAPIMethodListLogs HostAPIMethod = "logs/list" // HostAPIMethodSkillsList lists skills. HostAPIMethodSkillsList HostAPIMethod = "skills/list" // HostAPIMethodNetworkStatus returns network runtime status. HostAPIMethodNetworkStatus HostAPIMethod = "network/status" // HostAPIMethodNetworkChannels lists network channels. HostAPIMethodNetworkChannels HostAPIMethod = "network/channels" // HostAPIMethodNetworkPeers lists visible network peers. HostAPIMethodNetworkPeers HostAPIMethod = "network/peers" // HostAPIMethodNetworkThreads lists public network threads. HostAPIMethodNetworkThreads HostAPIMethod = "network/threads" // HostAPIMethodNetworkThreadGet returns one public network thread. HostAPIMethodNetworkThreadGet HostAPIMethod = "network/thread/get" // HostAPIMethodNetworkThreadMessages lists messages inside one public network thread. HostAPIMethodNetworkThreadMessages HostAPIMethod = "network/thread/messages" // HostAPIMethodNetworkDirects lists network direct rooms. HostAPIMethodNetworkDirects HostAPIMethod = "network/directs" // HostAPIMethodNetworkDirectResolve resolves a deterministic two-party direct room. HostAPIMethodNetworkDirectResolve HostAPIMethod = "network/direct/resolve" // HostAPIMethodNetworkDirectMessages lists messages inside one direct room. HostAPIMethodNetworkDirectMessages HostAPIMethod = "network/direct/messages" // HostAPIMethodNetworkWorkGet returns one network work row. HostAPIMethodNetworkWorkGet HostAPIMethod = "network/work/get" // HostAPIMethodNetworkSend sends one network message. HostAPIMethodNetworkSend HostAPIMethod = "network/send" // HostAPIMethodResourcesList lists resources. HostAPIMethodResourcesList HostAPIMethod = "resources/list" // HostAPIMethodResourcesGet fetches one resource. HostAPIMethodResourcesGet HostAPIMethod = "resources/get" // HostAPIMethodResourcesSnapshot snapshots resources. HostAPIMethodResourcesSnapshot HostAPIMethod = "resources/snapshot" )
type InitializeCapabilities ¶
type InitializeCapabilities struct {
Provides []string `json:"provides"`
GrantedActions []HostAPIMethod `json:"granted_actions"`
GrantedSecurity []string `json:"granted_security"`
GrantedResourceKinds []string `json:"granted_resource_kinds"`
GrantedResourceScopes []string `json:"granted_resource_scopes"`
}
InitializeCapabilities carries runtime-granted capabilities.
type InitializeExtension ¶
type InitializeExtension struct {
Name string `json:"name"`
Version string `json:"version"`
SourceTier string `json:"source_tier"`
}
InitializeExtension identifies the launched extension.
type InitializeExtensionInfo ¶
type InitializeExtensionInfo struct {
Name string `json:"name"`
Version string `json:"version"`
SDKName string `json:"sdk_name,omitempty"`
SDKVersion string `json:"sdk_version,omitempty"`
}
InitializeExtensionInfo identifies the running extension implementation.
type InitializeMethods ¶
type InitializeMethods struct {
DaemonRequests []string `json:"daemon_requests"`
ExtensionServices []string `json:"extension_services"`
}
InitializeMethods lists callable method families for the session.
type InitializeRequest ¶
type InitializeRequest struct {
ProtocolVersion string `json:"protocol_version"`
SupportedProtocolVersions []string `json:"supported_protocol_versions"`
AGHVersion string `json:"agh_version"`
SessionNonce string `json:"session_nonce"`
Extension InitializeExtension `json:"extension"`
Capabilities InitializeCapabilities `json:"capabilities"`
Methods InitializeMethods `json:"methods"`
Runtime InitializeRuntime `json:"runtime"`
}
InitializeRequest is the AGH -> extension session contract request.
type InitializeResponse ¶
type InitializeResponse struct {
ProtocolVersion string `json:"protocol_version"`
ExtensionInfo InitializeExtensionInfo `json:"extension_info"`
AcceptedCapabilities AcceptedCapabilities `json:"accepted_capabilities"`
ImplementedMethods []string `json:"implemented_methods"`
SupportedHookEvents []string `json:"supported_hook_events"`
Supports InitializeSupports `json:"supports"`
}
InitializeResponse is the extension -> AGH initialize acknowledgment.
type InitializeRuntime ¶
type InitializeRuntime struct {
HealthCheckIntervalMS int64 `json:"health_check_interval_ms"`
HealthCheckTimeoutMS int64 `json:"health_check_timeout_ms"`
ShutdownTimeoutMS int64 `json:"shutdown_timeout_ms"`
DefaultHookTimeoutMS int64 `json:"default_hook_timeout_ms"`
Bridge json.RawMessage `json:"bridge,omitempty"`
}
InitializeRuntime carries runtime intervals and deadlines.
type InitializeSupports ¶
type InitializeSupports struct {
HealthCheck bool `json:"health_check"`
}
InitializeSupports advertises optional protocol features.
type JSONRPCErrorObject ¶
type JSONRPCErrorObject struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
JSONRPCErrorObject is the wire error object used by JSON-RPC 2.0.
type JSONRPCRequestEnvelope ¶
type JSONRPCRequestEnvelope struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
JSONRPCRequestEnvelope is the public request metadata visible to handlers.
type Option ¶
type Option func(*Extension)
Option configures an Extension.
func WithSDKVersion ¶
WithSDKVersion overrides the advertised SDK version.
func WithStderr ¶
WithStderr sets the log sink used by ExtensionContext.Logf.
func WithTransport ¶
WithTransport sets a custom JSON-RPC transport.
type RPCError ¶
type RPCError struct {
Code int
Message string
Data json.RawMessage
}
RPCError is a typed JSON-RPC error.
func NewCapabilityDeniedError ¶
NewCapabilityDeniedError creates a capability denied error.
func NewInternalError ¶
NewInternalError creates an Internal error.
func NewInvalidParamsError ¶
NewInvalidParamsError creates an Invalid params error.
func NewInvalidRequestError ¶
NewInvalidRequestError creates an Invalid request error.
func NewMethodNotFoundError ¶
NewMethodNotFoundError creates a Method not found error.
func NewNotInitializedError ¶
func NewNotInitializedError() *RPCError
NewNotInitializedError creates a not-initialized error.
func NewRPCError ¶
NewRPCError creates a typed JSON-RPC error with optional data.
func NewShutdownInProgressError ¶
NewShutdownInProgressError creates a shutdown-in-progress error.
func NewToolExecutionError ¶
NewToolExecutionError creates a tool execution error.
type Redaction ¶
type Redaction struct {
Path string `json:"path"`
Reason string `json:"reason"`
Bytes int64 `json:"bytes,omitempty"`
}
Redaction records a redaction applied to a result.
type SecurityConfig ¶
type SecurityConfig struct {
Capabilities []string `json:"capabilities,omitempty"`
}
SecurityConfig lists required security grants.
type ShutdownRequest ¶
ShutdownRequest is sent before signal escalation.
type ShutdownResponse ¶
type ShutdownResponse struct {
Acknowledged bool `json:"acknowledged"`
}
ShutdownResponse acknowledges cooperative shutdown.
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport is a newline-delimited JSON-RPC 2.0 transport over stdio.
func NewStdioTransport ¶
func NewStdioTransport(options StdioTransportOptions) *StdioTransport
NewStdioTransport creates a stdio JSON-RPC transport.
func (*StdioTransport) Close ¶
func (t *StdioTransport) Close() error
Close closes the transport and rejects pending calls.
func (*StdioTransport) Handle ¶
func (t *StdioTransport) Handle(method string, handler TransportHandler)
Handle registers or replaces an inbound method handler.
type StdioTransportOptions ¶
StdioTransportOptions configures a StdioTransport.
type ToolContent ¶
type ToolContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
Metadata map[string]json.RawMessage `json:"metadata,omitempty"`
}
ToolContent is one typed content block returned by a tool.
type ToolHandlerFunc ¶
type ToolHandlerFunc[TInput any] func(context.Context, ToolRequest[TInput]) (ToolResult, error)
ToolHandlerFunc handles one typed tool request.
type ToolOptions ¶
type ToolOptions struct {
ID ToolID
Description string
InputSchema any
OutputSchema any
ReadOnly bool
Risk RiskClass
Capabilities []string
SensitiveInputFields []string
}
ToolOptions configures one function-backed extension tool.
type ToolRequest ¶
type ToolRequest[TInput any] struct { Input TInput RawInput json.RawMessage Context ExtensionContext Host *HostAPI Session ExtensionSession ToolID ToolID Handler string }
ToolRequest is passed to a typed tool handler.
type ToolResult ¶
type ToolResult struct {
Content []ToolContent `json:"content,omitempty"`
Structured json.RawMessage `json:"structured,omitempty"`
Preview string `json:"preview,omitempty"`
Artifacts []ArtifactRef `json:"artifacts,omitempty"`
Metadata map[string]json.RawMessage `json:"metadata,omitempty"`
Redactions []Redaction `json:"redactions,omitempty"`
Truncated bool `json:"truncated"`
Bytes int64 `json:"bytes"`
DurationMS int64 `json:"duration_ms"`
}
ToolResult is the canonical result envelope for tool handlers.
func EmptyResult ¶
func EmptyResult() ToolResult
EmptyResult returns an empty successful tool result.
func StructuredResult ¶
func StructuredResult(value any) (ToolResult, error)
StructuredResult marshals a structured payload into the result envelope.
type Transport ¶
type Transport interface {
Handle(method string, handler TransportHandler)
Call(ctx context.Context, method string, params any, result any) error
Run(ctx context.Context) error
Close() error
}
Transport is the bidirectional JSON-RPC runtime used by Extension.
type TransportHandler ¶
type TransportHandler func(context.Context, json.RawMessage, JSONRPCRequestEnvelope) (any, error)
TransportHandler handles one inbound JSON-RPC request.