agent

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// EnableEventFiltering controls whether LLM nodes see filtered events (per-node history)
	// or full session history. Set to true for node isolation, false for full context.
	// TODO: Make this configurable per agent flow in the future
	EnableEventFiltering = true
)

Package-level map for session event tracking (persists across LiveSession instances)

View Source
var ErrWaitingForApproval = fmt.Errorf("interrupt: waiting for user approval")

ErrWaitingForApproval is returned when a tool needs user approval

Functions

func EvaluateCondition

func EvaluateCondition(conditionStr string, state map[string]interface{}) (bool, error)

EvaluateCondition evaluates a Python-style condition using Starlark

func EvaluateExpression

func EvaluateExpression(expr string, state map[string]interface{}) (interface{}, error)

EvaluateExpression evaluates a Python-style expression using Starlark and returns the result

Types

type AstonishAgent

type AstonishAgent struct {
	Config         *config.AgentConfig
	LLM            model.LLM
	Tools          []tool.Tool
	Toolsets       []tool.Toolset
	DebugMode      bool
	IsWebMode      bool // If true, avoids ANSI codes in output
	SessionService session.Service
}

AstonishAgent implements the logic for running Astonish agents.

func NewAstonishAgent

func NewAstonishAgent(cfg *config.AgentConfig, llm model.LLM, tools []tool.Tool) *AstonishAgent

NewAstonishAgent creates a new AstonishAgent.

func NewAstonishAgentWithToolsets

func NewAstonishAgentWithToolsets(cfg *config.AgentConfig, llm model.LLM, tools []tool.Tool, toolsets []tool.Toolset) *AstonishAgent

NewAstonishAgentWithToolsets creates a new AstonishAgent with both tools and toolsets.

func (*AstonishAgent) Run

Run executes the agent flow with stateful workflow management.

type ErrorContext

type ErrorContext struct {
	NodeName       string         `json:"node_name"`
	NodeType       string         `json:"node_type"`                // "llm", "tool", etc.
	ErrorType      string         `json:"error_type"`               // "tool_error", "parse_error", "llm_error", etc.
	ErrorMessage   string         `json:"error_message"`            // The actual error message
	AttemptCount   int            `json:"attempt_count"`            // Current retry attempt (1-indexed)
	MaxRetries     int            `json:"max_retries"`              // Configured maximum retries
	PreviousErrors []string       `json:"previous_errors"`          // History of error messages
	ToolName       string         `json:"tool_name,omitempty"`      // If tool error
	ToolArgs       map[string]any `json:"tool_args,omitempty"`      // If tool error
	OriginalInput  map[string]any `json:"original_input,omitempty"` // Original node inputs
}

ErrorContext captures the context of an error for recovery analysis

type ErrorRecoveryNode

type ErrorRecoveryNode struct {
	LLM       model.LLM
	DebugMode bool
}

ErrorRecoveryNode analyzes errors and decides whether to retry or abort

func NewErrorRecoveryNode

func NewErrorRecoveryNode(llm model.LLM, debugMode bool) *ErrorRecoveryNode

NewErrorRecoveryNode creates a new error recovery analyzer

func (*ErrorRecoveryNode) Decide

Decide analyzes an error and decides whether to retry or abort

type FilteredToolset

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

FilteredToolset wraps a toolset and filters tools based on allowed list

func (*FilteredToolset) Name

func (f *FilteredToolset) Name() string

Name returns the name of the underlying toolset

func (*FilteredToolset) Tools

func (f *FilteredToolset) Tools(ctx agent.ReadonlyContext) ([]tool.Tool, error)

Tools returns only the tools that are in the allowed list

type LiveSession

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

LiveSession wraps a session and fetches fresh data from the service on access It also tracks node boundaries for filtering events by current node

func (*LiveSession) AppName

func (s *LiveSession) AppName() string

func (*LiveSession) Events

func (s *LiveSession) Events() session.Events

func (*LiveSession) ID

func (s *LiveSession) ID() string

func (*LiveSession) LastUpdateTime

func (s *LiveSession) LastUpdateTime() time.Time

func (*LiveSession) State

func (s *LiveSession) State() session.State

func (*LiveSession) UserID

func (s *LiveSession) UserID() string

type ProtectedTool

type ProtectedTool struct {
	tool.Tool                                  // Embed the underlying tool
	State     session.State                    // Access to session state
	Agent     *AstonishAgent                   // Access to helper methods
	YieldFunc func(*session.Event, error) bool // For emitting events
}

ProtectedTool wraps a standard tool and adds an approval gate.

func (*ProtectedTool) Declaration

func (p *ProtectedTool) Declaration() *genai.FunctionDeclaration

Declaration forwards the call to the underlying tool if it supports it

func (*ProtectedTool) ProcessRequest

func (p *ProtectedTool) ProcessRequest(ctx tool.Context, req *model.LLMRequest) error

ProcessRequest always delegates to underlying tool to register it with the LLM Approval is checked later during Run(), not during ProcessRequest()

func (*ProtectedTool) Run

func (p *ProtectedTool) Run(ctx tool.Context, args any) (map[string]any, error)

Run intercepts the execution to check for approval

type ProtectedToolset

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

ProtectedToolset wraps a toolset and returns tools wrapped with ProtectedTool

func (*ProtectedToolset) Name

func (p *ProtectedToolset) Name() string

Name returns the name of the underlying toolset

func (*ProtectedToolset) Tools

func (p *ProtectedToolset) Tools(ctx agent.ReadonlyContext) ([]tool.Tool, error)

Tools returns the underlying toolset's tools, wrapped with ProtectedTool

type RecoveryDecision

type RecoveryDecision struct {
	ShouldRetry bool   `json:"should_retry"` // true = retry, false = abort
	Title       string `json:"title"`        // Short, clear summary of the error (max 100 chars)
	OneLiner    string `json:"one_liner"`    // Ultra-short summary for badges (max 60 chars)
	Reason      string `json:"reason"`       // Explanation of the decision
	Suggestion  string `json:"suggestion"`   // What to fix or try differently (if retry)
}

RecoveryDecision represents the decision made by the error recovery system

type RunnableTool

type RunnableTool interface {
	Run(ctx tool.Context, args any) (map[string]any, error)
}

RunnableTool defines an interface for tools that can be executed. This matches the signature of Run method in adk-go's internal tool implementations.

type ScopedContext

type ScopedContext struct {
	agent.InvocationContext
	// contains filtered or unexported fields
}

ScopedContext wraps an InvocationContext and overrides the state

func (*ScopedContext) Agent

func (s *ScopedContext) Agent() agent.Agent

func (*ScopedContext) Session

func (s *ScopedContext) Session() session.Session

func (*ScopedContext) SessionID

func (s *ScopedContext) SessionID() string

func (*ScopedContext) State

func (s *ScopedContext) State() session.State

type ScopedSession

type ScopedSession struct {
	session.Session
	// contains filtered or unexported fields
}

ScopedSession wraps a Session and overrides the state

func (*ScopedSession) State

func (s *ScopedSession) State() session.State

type ScopedState

type ScopedState struct {
	Parent session.State
	Local  map[string]any
}

ScopedState wraps a parent state and allows local overrides

func (*ScopedState) All

func (s *ScopedState) All() iter.Seq2[string, any]

func (*ScopedState) Delete

func (s *ScopedState) Delete(key string) error

func (*ScopedState) Get

func (s *ScopedState) Get(key string) (any, error)

func (*ScopedState) Set

func (s *ScopedState) Set(key string, value any) error

type ToolWithDeclaration

type ToolWithDeclaration interface {
	Declaration() *genai.FunctionDeclaration
}

ToolWithDeclaration allows inspecting the tool's schema

Jump to

Keyboard shortcuts

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