agent

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package agent sets up the ADK Go agent loop with tools, system prompt, and runner for the pi-go coding agent.

Index

Constants

View Source
const (
	// AppName is the ADK application name used for session management.
	AppName = "pi-go"

	// DefaultUserID is the default user ID for local single-user sessions.
	DefaultUserID = "local"
)
View Source
const SystemInstruction = `` /* 4101-byte string literal not displayed */

SystemInstruction is the default system prompt for the coding agent.

Variables

This section is empty.

Functions

func LoadInstruction

func LoadInstruction(baseInstruction string) string

LoadInstruction attempts to load an AGENTS.md file from the working directory and appends its content to the base instruction.

func WithRetry

func WithRetry(cfg RetryConfig, runFn func() iter.Seq2[*session.Event, error]) iter.Seq2[*session.Event, error]

WithRetry wraps an agent run function with retry logic for transient errors. If the iterator yields a transient error, it sleeps and retries the entire run. Non-transient errors are yielded immediately without retry.

Types

type AfterToolCallback

type AfterToolCallback = llmagent.AfterToolCallback

re-export callback types for use by CLI without importing llmagent directly.

type Agent

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

Agent wraps an ADK Runner and session management for the coding agent.

func New

func New(cfg Config) (*Agent, error)

New creates a new Agent with the given configuration.

func (*Agent) CreateSession

func (a *Agent) CreateSession(ctx context.Context) (string, error)

CreateSession creates a new session and returns its ID.

func (*Agent) RebuildWithInstruction

func (a *Agent) RebuildWithInstruction(instruction string) error

RebuildWithInstruction recreates the agent's internal runner with a new system instruction while preserving all other configuration (tools, callbacks, etc.). The session service is reused so existing sessions remain accessible.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, sessionID string, userMessage string) iter.Seq2[*session.Event, error]

Run sends a user message and returns an iterator over agent events. The caller should iterate over the returned sequence to process events.

func (*Agent) RunStreaming

func (a *Agent) RunStreaming(ctx context.Context, sessionID string, userMessage string) iter.Seq2[*session.Event, error]

RunStreaming sends a user message with SSE streaming enabled.

type BeforeToolCallback

type BeforeToolCallback = llmagent.BeforeToolCallback

re-export callback types for use by CLI without importing llmagent directly.

type Config

type Config struct {
	// Model is the LLM provider to use (implements model.LLM).
	Model model.LLM

	// Tools are the tools available to the agent.
	Tools []tool.Tool

	// Toolsets are additional tool providers (e.g. MCP toolsets).
	Toolsets []tool.Toolset

	// Instruction overrides the default system instruction.
	// If empty, SystemInstruction is used.
	Instruction string

	// SessionService overrides the default in-memory session service.
	// If nil, an in-memory service is created.
	SessionService session.Service

	// BeforeToolCallbacks run before each tool execution.
	BeforeToolCallbacks []BeforeToolCallback

	// AfterToolCallbacks run after each tool execution.
	AfterToolCallbacks []AfterToolCallback
}

Config holds configuration for creating a new Agent.

type RetryConfig

type RetryConfig struct {
	// MaxRetries is the maximum number of retry attempts (default 3).
	MaxRetries int

	// InitialDelay is the base delay before the first retry (default 1s).
	InitialDelay time.Duration

	// MaxDelay caps the exponential backoff delay (default 30s).
	MaxDelay time.Duration
}

RetryConfig controls retry behavior for transient LLM errors.

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible defaults for retry behavior.

Jump to

Keyboard shortcuts

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