agentboot

package
v0.260224.1130 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

README ¶

AgentBoot Package

AgentBoot is a unified agent bootstrapping and management package that provides a clean abstraction for running different AI coding agents.

Features

  • Unified Agent Interface: Common interface for all agent types
  • Stream-JSON Support: Real-time event streaming for rich output
  • Permission Management: Flexible permission handling with multiple modes
  • Extensible Design: Easy to add new agent types
  • Configuration: Environment-based configuration

Supported Agents

Agent Status Description
claude ✅ Implemented Claude Code CLI
codex 🚧 Planned OpenAI Codex
gemini 🚧 Planned Google Gemini
cursor 🚧 Planned Cursor AI

Usage

Basic Usage
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    _ "github.com/tingly-dev/tingly-box/agentboot/claude" // Import to register Claude agent
)

func main() {
    // Create AgentBoot instance
    ab := agentboot.New(agentboot.Config{
        DefaultAgent:     agentboot.AgentTypeClaude,
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    })

    // Register Claude agent (or use agents that have auto-registered via init())
    claudeAgent := claude.NewAgent(ab.GetConfig())
    ab.RegisterAgent(agentboot.AgentTypeClaude, claudeAgent)

    // Get Claude agent
    agent, err := ab.GetAgent(agentboot.AgentTypeClaude)
    if err != nil {
        log.Fatal(err)
    }

    // Execute prompt
    result, err := agent.Execute(context.Background(), "Say hello", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.TextOutput())
}
Alternative: Using Claude Agent Directly
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    "github.com/tingly-dev/tingly-box/agentboot/claude"
)

func main() {
    // Create config
    config := agentboot.Config{
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    }

    // Create Claude agent directly
    agent := claude.NewAgent(config)

    // Execute prompt
    result, err := agent.Execute(context.Background(), "Say hello", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.TextOutput())
}
With Permission Handler
package main

import (
    "context"
    "log"

    "github.com/tingly-dev/tingly-box/agentboot"
    "github.com/tingly-dev/tingly-box/agentboot/claude"
    "github.com/tingly-dev/tingly-box/agentboot/permission"
)

func main() {
    // Create configuration
    config := agentboot.Config{
        DefaultFormat:    agentboot.OutputFormatStreamJSON,
        EnableStreamJSON: true,
    }

    // Create permission handler
    permHandler := permission.NewDefaultHandler(permission.Config{
        DefaultMode: agentboot.PermissionModeManual,
        Timeout:     300, // 5 minutes
    })

    // Create agent with permission handler
    agent := claude.NewAgentWithPermissionHandler(config, permHandler)

    // Set permission mode for a session
    permHandler.SetMode("session-123", agentboot.PermissionModeAuto)

    // Execute prompt
    result, err := agent.Execute(context.Background(), "List files", agentboot.ExecutionOptions{
        OutputFormat: agentboot.OutputFormatStreamJSON,
    })

    if err != nil {
        log.Fatal(err)
    }

    log.Println(result.TextOutput())
}

Output Formats

Text Format

Simple text output (default):

claude --print --output-format text "Say hello"
Stream-JSON Format

Rich event streaming:

claude --output-format stream-json --verbose --print "Say hello"

Event types:

  • text_delta - Incremental text output
  • tool_call_start - Tool invocation begins
  • tool_call_end - Tool completes
  • permission_request - Permission needed
  • status - Agent status change
  • thinking - Reasoning state

Permission Modes

Mode Description
auto Auto-approve all requests
manual Require user approval
skip Skip permission prompts

Configuration

Environment Variables
Variable Description Default
AGENTBOOT_DEFAULT_AGENT Default agent type claude
AGENTBOOT_DEFAULT_FORMAT Default output format text
AGENTBOOT_ENABLE_STREAM_JSON Enable stream-json true
AGENTBOOT_STREAM_BUFFER_SIZE Event buffer size 100
RCC_PERMISSION_MODE Permission mode auto
RCC_PERMISSION_TIMEOUT Approval timeout 5m
RCC_WHITELIST Whitelisted tools
RCC_BLACKLIST Blacklisted tools

Package Structure

agentboot/
├── agentboot.go      # Core package and factory
├── types.go          # Common types and interfaces
├── config.go         # Configuration
├── events/           # Event streaming
│   ├── events.go     # Event interfaces
│   ├── parser.go     # Stream parser
│   └── bus.go        # Event bus
├── permission/       # Permission management
│   ├── handler.go    # Permission handler interface
│   ├── handler_impl.go # Default implementation
│   └── store.go      # Permission history storage
└── claude/           # Claude Code agent
    ├── agent.go      # Claude agent
    ├── launcher.go   # Process launcher
    ├── config.go     # Claude config
    └── events.go     # Claude event types

Adding a New Agent

  1. Create agent package: agentboot/youragent/

  2. Implement agent.Agent interface:

type Agent struct {
    launcher *Launcher
}

func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.Result, error)
func (a *Agent) IsAvailable() bool
func (a *Agent) Type() agentboot.AgentType
func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
  1. Register in agentboot.go:
ab.agents[AgentTypeYourAgent] = youragent.NewAgent(ab.config)

License

MIT

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Agent ¶

type Agent interface {
	// Execute runs the agent with the given prompt
	Execute(ctx context.Context, prompt string, opts ExecutionOptions) (*Result, error)

	// IsAvailable checks if the agent is available
	IsAvailable() bool

	// Type returns the agent type
	Type() AgentType

	// SetDefaultFormat sets the default output format
	SetDefaultFormat(format OutputFormat)

	// GetDefaultFormat returns the current default format
	GetDefaultFormat() OutputFormat
}

Agent is the interface for all agent types

type AgentBoot ¶

type AgentBoot struct {
	// contains filtered or unexported fields
}

AgentBoot manages agent instances

func New ¶

func New(config Config) *AgentBoot

New creates a new AgentBoot instance

func (*AgentBoot) GetAgent ¶

func (ab *AgentBoot) GetAgent(agentType AgentType) (Agent, error)

GetAgent returns an agent by type

func (*AgentBoot) GetConfig ¶

func (ab *AgentBoot) GetConfig() Config

GetConfig returns the current configuration

func (*AgentBoot) GetDefaultAgent ¶

func (ab *AgentBoot) GetDefaultAgent() (Agent, error)

GetDefaultAgent returns the default agent

func (*AgentBoot) ListAgents ¶

func (ab *AgentBoot) ListAgents() []AgentType

ListAgents returns all registered agent types

func (*AgentBoot) MustGetAgent ¶

func (ab *AgentBoot) MustGetAgent(agentType AgentType) Agent

MustGetAgent returns an agent by type or panics

func (*AgentBoot) RegisterAgent ¶

func (ab *AgentBoot) RegisterAgent(agentType AgentType, agent Agent)

RegisterAgent registers a new agent type

func (*AgentBoot) SetDefaultAgent ¶

func (ab *AgentBoot) SetDefaultAgent(agentType AgentType) error

SetDefaultAgent sets the default agent type

type AgentType ¶

type AgentType string

AgentType defines the supported agent types

const (
	AgentTypeClaude AgentType = "claude"
)

func (AgentType) String ¶

func (t AgentType) String() string

String returns the string representation of AgentType

type CompletionResult ¶

type CompletionResult struct {
	Success    bool
	DurationMS int64
	SessionID  string
	Error      string
}

CompletionResult contains the final result information

type Config ¶

type Config struct {
	DefaultAgent     AgentType    `json:"default_agent"`
	DefaultFormat    OutputFormat `json:"default_format"`
	EnableStreamJSON bool         `json:"enable_stream_json"`
	StreamBufferSize int          `json:"stream_buffer_size"`
}

Config holds the AgentBoot configuration

func DefaultConfig ¶

func DefaultConfig() Config

DefaultConfig returns the default AgentBoot configuration

type Event ¶

type Event struct {
	Type      string                 `json:"type"`
	Data      map[string]interface{} `json:"data"`
	Timestamp time.Time              `json:"timestamp"`
	Raw       string                 `json:"raw,omitempty"`
}

Event represents a generic agent event

type ExecutionOptions ¶

type ExecutionOptions struct {
	ProjectPath  string
	OutputFormat OutputFormat
	Timeout      time.Duration
	Env          []string
	// Handler is an optional message handler for real-time processing
	// If provided, messages will be streamed to the handler during execution
	Handler MessageHandler
	// SessionID is the session ID to use or resume
	// If Resume is true, --resume <session_id> is used to continue an existing session
	// If Resume is false, --session-id <session_id> is used to create a new session with specific ID
	SessionID string
	// Resume indicates whether to resume an existing session (true) or create a new one (false)
	Resume bool
}

ExecutionOptions controls agent execution

type MessageHandler ¶

type MessageHandler interface {
	OnMessage(msg interface{}) error
	OnError(err error)
	OnComplete(result *CompletionResult)
}

MessageHandler is the interface for real-time message processing This interface is defined here to avoid circular dependencies

type OutputFormat ¶

type OutputFormat string

OutputFormat defines agent output format

const (
	OutputFormatText       OutputFormat = "text"
	OutputFormatStreamJSON OutputFormat = "stream-json"
)

func (OutputFormat) String ¶

func (f OutputFormat) String() string

String returns the string representation of OutputFormat

type PermissionConfig ¶

type PermissionConfig struct {
	DefaultMode       PermissionMode `json:"default_mode"`
	Timeout           time.Duration  `json:"timeout"`
	EnableWhitelist   bool           `json:"enable_whitelist"`
	Whitelist         []string       `json:"whitelist"`
	Blacklist         []string       `json:"blacklist"`
	RememberDecisions bool           `json:"remember_decisions"`
	DecisionDuration  time.Duration  `json:"decision_duration"`
}

PermissionConfig holds permission handler configuration

func DefaultPermissionConfig ¶

func DefaultPermissionConfig() PermissionConfig

DefaultPermissionConfig returns the default permission handler configuration

type PermissionMode ¶

type PermissionMode string

PermissionMode defines how permission requests are handled

const (
	PermissionModeAuto   PermissionMode = "auto"   // Auto-approve all requests
	PermissionModeManual PermissionMode = "manual" // Require user approval
	PermissionModeSkip   PermissionMode = "skip"   // Skip permission prompts
)

func ParsePermissionMode ¶

func ParsePermissionMode(s string) (PermissionMode, bool)

ParsePermissionMode parses a permission mode from string

func (PermissionMode) String ¶

func (m PermissionMode) String() string

String returns the string representation of PermissionMode

type PermissionRequest ¶

type PermissionRequest struct {
	RequestID string                 `json:"request_id"`
	AgentType AgentType              `json:"agent_type"`
	ToolName  string                 `json:"tool_name"`
	Input     map[string]interface{} `json:"input"`
	Reason    string                 `json:"reason,omitempty"`
	Timestamp time.Time              `json:"timestamp"`
	SessionID string                 `json:"session_id,omitempty"`
}

PermissionRequest represents a permission request from an agent

type PermissionResponse ¶

type PermissionResponse struct {
	RequestID string    `json:"request_id"`
	Approved  bool      `json:"approved"`
	Reason    string    `json:"reason,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

PermissionResponse represents the response to a permission request

type PermissionResult ¶

type PermissionResult struct {
	Approved bool   `json:"approved"`
	Reason   string `json:"reason,omitempty"`
}

PermissionResult represents the result of a permission check

type Result ¶

type Result struct {
	Output   string // Agent output (text mode)
	ExitCode int    // Process exit code
	Error    string // Error message if failed
	Duration time.Duration
	Format   OutputFormat           // Output format used
	Events   []Event                // Stream events (stream-json mode)
	Metadata map[string]interface{} // Additional metadata
}

Result represents the result of an agent execution

func (*Result) GetAssistantMessages ¶

func (r *Result) GetAssistantMessages() []Event

GetAssistantMessages returns all assistant message events

func (*Result) GetCostUSD ¶

func (r *Result) GetCostUSD() float64

GetCostUSD extracts the total cost from result events if available

func (*Result) GetMessageChain ¶

func (r *Result) GetMessageChain() []Event

GetMessageChain returns all events in order, excluding result/system events

func (*Result) GetMessagesByType ¶

func (r *Result) GetMessagesByType(messageType string) []Event

GetMessagesByType returns all events of a specific type

func (*Result) GetSessionID ¶

func (r *Result) GetSessionID() string

GetSessionID extracts the session ID from metadata or events

func (*Result) GetStatus ¶

func (r *Result) GetStatus() string

GetStatus extracts the final status from events

func (*Result) GetToolResultMessages ¶

func (r *Result) GetToolResultMessages() []Event

GetToolResultMessages returns all tool_result message events

func (*Result) GetToolUseMessages ¶

func (r *Result) GetToolUseMessages() []Event

GetToolUseMessages returns all tool_use message events

func (*Result) GetUserMessages ¶

func (r *Result) GetUserMessages() []Event

GetUserMessages returns all user message events

func (*Result) IsSuccess ¶

func (r *Result) IsSuccess() bool

IsSuccess returns true if the execution was successful

func (*Result) TextOutput ¶

func (r *Result) TextOutput() string

TextOutput returns the full text output from the result

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL