Documentation
¶
Overview ¶
Package agentkit provides a compact Go SDK for building agent runtimes on top of Claude and OpenAI style streaming model APIs.
The root package intentionally keeps the public surface flat: agent/session orchestration, message and event models, provider abstractions, and shared runtime helpers all live here. Provider adapters and local tools stay in dedicated subpackages.
Index ¶
- Constants
- Variables
- func AgentTool(agent *Agent, description string) toolpkg.Definition
- func RegisterProvider(name string, loader ProviderLoader)
- type Agent
- type AtomicSessionStore
- type ContentBlock
- type ContentBlockType
- type ContextTruncator
- type Event
- type EventStream
- type EventType
- type ImageSource
- type MemoryStore
- func (s *MemoryStore) AtomicUpdate(_ context.Context, agentID, sessionID string, ...) (SessionRecord, error)
- func (s *MemoryStore) Create(_ context.Context, record SessionRecord) error
- func (s *MemoryStore) Delete(_ context.Context, agentID, sessionID string) error
- func (s *MemoryStore) Get(_ context.Context, agentID, sessionID string) (SessionRecord, error)
- func (s *MemoryStore) Put(_ context.Context, record SessionRecord) error
- type Message
- func AssistantMessage(text string) Message
- func AssistantMessageWithBlocks(blocks ...ContentBlock) Message
- func UserMessage(text string) Message
- func UserMessageWithBlocks(blocks ...ContentBlock) Message
- func UserMessageWithImage(text, imageURL string) Message
- func UserMessageWithImageData(text, mediaType string, data []byte) Message
- type Option
- func WithID(id string) Option
- func WithInstructions(instructions string) Option
- func WithModel(model string) Option
- func WithName(name string) Option
- func WithProvider(provider Provider) Option
- func WithSessionManager(manager *SessionManager) Option
- func WithTelemetry(telemetry Telemetry) Option
- func WithTools(definitions ...toolpkg.Definition) Option
- func WithWorkspace(workspace WorkspaceConfig) Option
- type Provider
- type ProviderCallTrace
- type ProviderLoader
- type Query
- type QueryOptions
- type Request
- type Role
- type Session
- func (s *Session) Close() error
- func (s *Session) Fork(ctx context.Context) (*Session, error)
- func (s *Session) History() []Message
- func (s *Session) ID() string
- func (s *Session) Info() SessionInfo
- func (s *Session) State() SessionState
- func (s *Session) Stream(ctx context.Context, input Message) EventStream
- func (s *Session) Turns() []TurnRecord
- type SessionInfo
- type SessionManager
- type SessionRecord
- type SessionState
- type SessionStore
- type SessionUsageSummary
- type SlidingWindowTruncator
- type Telemetry
- type ToolChoice
- type ToolChoiceMode
- type ToolDefinition
- type ToolExecutionTrace
- type ToolResult
- type ToolUse
- type TurnRecord
- type TurnTrace
- type Usage
- type WorkspaceConfig
Constants ¶
const SessionStateVersion = 2
Variables ¶
Functions ¶
func RegisterProvider ¶
func RegisterProvider(name string, loader ProviderLoader)
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) CreateSession ¶
func (*Agent) DefaultSession ¶
func (*Agent) ResumeSession ¶
type AtomicSessionStore ¶
type AtomicSessionStore interface {
AtomicUpdate(context.Context, string, string, func(*SessionRecord) error) (SessionRecord, error)
}
type ContentBlock ¶
type ContentBlock struct {
Type ContentBlockType `json:"type"`
Text string `json:"text,omitempty"`
Image *ImageSource `json:"image,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
Data string `json:"data,omitempty"`
ToolUse *ToolUse `json:"tool_use,omitempty"`
ToolResult *ToolResult `json:"tool_result,omitempty"`
}
func ImageDataBlock ¶
func ImageDataBlock(mediaType string, data []byte) ContentBlock
func ImageURLBlock ¶
func ImageURLBlock(url string) ContentBlock
func TextBlock ¶
func TextBlock(text string) ContentBlock
func ToolResultBlock ¶
func ToolResultBlock(toolUseID, name, content string, isError bool) ContentBlock
func ToolUseBlock ¶
func ToolUseBlock(id, name string, input []byte) ContentBlock
type ContentBlockType ¶
type ContentBlockType string
const ( ContentBlockTypeText ContentBlockType = "text" ContentBlockTypeImage ContentBlockType = "image" ContentBlockTypeThinking ContentBlockType = "thinking" ContentBlockTypeRedactedThinking ContentBlockType = "redacted_thinking" ContentBlockTypeToolUse ContentBlockType = "tool_use" ContentBlockTypeToolResult ContentBlockType = "tool_result" ContentBlockTypeServerToolUse ContentBlockType = "server_tool_use" )
type ContextTruncator ¶
type Event ¶
type Event struct {
Type EventType `json:"type"`
TurnID uint64 `json:"turn_id,omitempty"`
Text string `json:"text,omitempty"`
ToolUse *ToolUse `json:"tool_use,omitempty"`
ToolResult *ToolResult `json:"tool_result,omitempty"`
Message *Message `json:"message,omitempty"`
Usage *Usage `json:"usage,omitempty"`
StopReason string `json:"stop_reason,omitempty"`
}
type ImageSource ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) AtomicUpdate ¶
func (s *MemoryStore) AtomicUpdate(_ context.Context, agentID, sessionID string, update func(*SessionRecord) error) (SessionRecord, error)
func (*MemoryStore) Create ¶
func (s *MemoryStore) Create(_ context.Context, record SessionRecord) error
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(_ context.Context, agentID, sessionID string) error
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(_ context.Context, agentID, sessionID string) (SessionRecord, error)
func (*MemoryStore) Put ¶
func (s *MemoryStore) Put(_ context.Context, record SessionRecord) error
type Message ¶
type Message struct {
Role Role `json:"role"`
Content []ContentBlock `json:"content"`
}
func AssistantMessage ¶
func AssistantMessageWithBlocks ¶
func AssistantMessageWithBlocks(blocks ...ContentBlock) Message
func UserMessage ¶
func UserMessageWithBlocks ¶
func UserMessageWithBlocks(blocks ...ContentBlock) Message
func UserMessageWithImage ¶
type Option ¶
func WithInstructions ¶
func WithProvider ¶
func WithSessionManager ¶
func WithSessionManager(manager *SessionManager) Option
func WithTelemetry ¶
func WithTools ¶
func WithTools(definitions ...toolpkg.Definition) Option
func WithWorkspace ¶
func WithWorkspace(workspace WorkspaceConfig) Option
type Provider ¶
type Provider interface {
Generate(context.Context, string, Request) EventStream
}
Provider generates model events for a normalized Request.
type ProviderCallTrace ¶
type ProviderLoader ¶
ProviderLoader constructs a Provider on demand, typically from environment configuration or an SDK client factory.
type Query ¶
type Query struct {
Prompt string `json:"prompt,omitempty"`
Input *Message `json:"input,omitempty"`
Options QueryOptions `json:"options,omitempty"`
}
type QueryOptions ¶
type QueryOptions struct {
History []Message `json:"history,omitempty"`
AllowedTools []string `json:"allowed_tools,omitempty"`
Model string `json:"model,omitempty"`
MaxTurns int `json:"max_turns,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
ToolChoice *ToolChoice `json:"tool_choice,omitempty"`
BudgetTokens int `json:"budget_tokens,omitempty"`
ContextTruncator ContextTruncator `json:"-"`
}
type Request ¶
type Request struct {
Query Query `json:"query"`
Instructions string `json:"instructions,omitempty"`
Tools []ToolDefinition `json:"tools,omitempty"`
}
Request is the normalized provider request produced by the agent runtime. Provider implementations should only depend on this shape rather than provider-specific SDK structs leaking into application code.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) Info ¶
func (s *Session) Info() SessionInfo
func (*Session) State ¶
func (s *Session) State() SessionState
func (*Session) Turns ¶
func (s *Session) Turns() []TurnRecord
type SessionInfo ¶
type SessionInfo struct {
SessionID string `json:"session_id"`
AgentID string `json:"agent_id"`
ParentSessionID string `json:"parent_session_id,omitempty"`
Model string `json:"model,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DirectUsage SessionUsageSummary `json:"direct_usage,omitempty"`
TotalUsage SessionUsageSummary `json:"total_usage,omitempty"`
}
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager(store SessionStore) *SessionManager
type SessionRecord ¶
type SessionRecord struct {
SessionID string `json:"session_id"`
AgentID string `json:"agent_id"`
ParentSessionID string `json:"parent_session_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
State SessionState `json:"state"`
InstructionSnapshot string `json:"instruction_snapshot,omitempty"`
BaseUsage SessionUsageSummary `json:"base_usage,omitempty"`
Turns []TurnRecord `json:"turns,omitempty"`
}
type SessionState ¶
type SessionState struct {
Version int `json:"version"`
History []Message `json:"history,omitempty"`
AllowedTools []string `json:"allowed_tools,omitempty"`
Model string `json:"model,omitempty"`
MaxTurns int `json:"max_turns,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
ToolChoice *ToolChoice `json:"tool_choice,omitempty"`
BudgetTokens int `json:"budget_tokens,omitempty"`
}
type SessionStore ¶
type SessionUsageSummary ¶
type SessionUsageSummary struct {
TurnCount int `json:"turn_count"`
CacheReadTurnCount int `json:"cache_read_turn_count"`
CacheCreationTurnCount int `json:"cache_creation_turn_count"`
InputTokens *int64 `json:"input_tokens,omitempty"`
OutputTokens *int64 `json:"output_tokens,omitempty"`
TotalTokens *int64 `json:"total_tokens,omitempty"`
CacheReadInputTokens *int64 `json:"cache_read_input_tokens,omitempty"`
CacheCreationInputTokens *int64 `json:"cache_creation_input_tokens,omitempty"`
}
type SlidingWindowTruncator ¶
type SlidingWindowTruncator struct {
MaxMessages int
}
type Telemetry ¶
type Telemetry interface {
OnProviderCall(context.Context, ProviderCallTrace)
OnToolExecution(context.Context, ToolExecutionTrace)
OnTurnComplete(context.Context, TurnTrace)
}
type ToolChoice ¶
type ToolChoice struct {
Mode ToolChoiceMode `json:"mode,omitempty"`
Name string `json:"name,omitempty"`
}
type ToolChoiceMode ¶
type ToolChoiceMode string
const ( ToolChoiceModeAuto ToolChoiceMode = "auto" ToolChoiceModeRequired ToolChoiceMode = "required" ToolChoiceModeNone ToolChoiceMode = "none" )
type ToolDefinition ¶
type ToolExecutionTrace ¶
type ToolResult ¶
type TurnRecord ¶
type Usage ¶
type Usage struct {
InputTokens *int64 `json:"input_tokens,omitempty"`
OutputTokens *int64 `json:"output_tokens,omitempty"`
TotalTokens *int64 `json:"total_tokens,omitempty"`
CacheReadInputTokens *int64 `json:"cache_read_input_tokens,omitempty"`
CacheCreationInputTokens *int64 `json:"cache_creation_input_tokens,omitempty"`
}
func AccumulateUsage ¶
func MergeUsage ¶
func NormalizeUsage ¶
func (*Usage) HasCacheCreation ¶
func (*Usage) HasCacheRead ¶
type WorkspaceConfig ¶
type WorkspaceConfig struct {
Root string `json:"root,omitempty"`
}
WorkspaceConfig controls workspace-scoped instruction loading.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
multi_agent
command
|
|
|
streaming_input
command
|
|
|
tools
command
|
|
|
provider
|
|
|
claude
Package claude provides the Anthropic Claude adapter for agentkit.
|
Package claude provides the Anthropic Claude adapter for agentkit. |
|
openai
Package openai provides the OpenAI Responses API adapter for agentkit.
|
Package openai provides the OpenAI Responses API adapter for agentkit. |
|
openaichat
Package openaichat provides the OpenAI Chat Completions adapter for agentkit.
|
Package openaichat provides the OpenAI Chat Completions adapter for agentkit. |
|
Package tool defines tool handlers and the built-in local tools used by agentkit runtimes.
|
Package tool defines tool handlers and the built-in local tools used by agentkit runtimes. |