native

package
v0.82.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSessionEventStoreUnavailable indicates that session branch controls require a configured event store.
	ErrSessionEventStoreUnavailable = errors.New("session event store is not configured")
	// ErrSessionIDRequired indicates that a session control call needs either an explicit session ID or Config.SessionID.
	ErrSessionIDRequired = errors.New("session id is required")
	// ErrSessionBranchIDRequired indicates that a branch switch was requested without a target branch ID.
	ErrSessionBranchIDRequired = errors.New("session branch id is required")
)

Functions

This section is empty.

Types

type Agent

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

Agent executes tasks using provider-native tool calling with a shared dspy-go harness.

func NewAgent

func NewAgent(llm core.LLM, cfg Config) (*Agent, error)

NewAgent creates a shared native tool-calling agent.

func (*Agent) Clone

func (a *Agent) Clone() (optimize.OptimizableAgent, error)

Clone creates a fresh agent with the same LLM, config, and registered tools.

func (*Agent) Execute

func (a *Agent) Execute(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)

Execute runs one native tool-calling task.

func (*Agent) ForkActiveSession added in v0.82.0

func (a *Agent) ForkActiveSession(ctx context.Context, sessionID, name string, setActive bool) (*sessionevent.SessionBranch, error)

ForkActiveSession creates a branch from the current active head. When setActive is true, the new branch becomes the session's active branch immediately.

func (*Agent) GetArtifacts

func (a *Agent) GetArtifacts() optimize.AgentArtifacts

GetArtifacts returns prompt/config backed artifacts.

func (*Agent) GetCapabilities

func (a *Agent) GetCapabilities() []core.Tool

GetCapabilities returns the currently registered tools.

func (*Agent) GetMemory

func (a *Agent) GetMemory() agents.Memory

GetMemory returns the attached memory store.

func (*Agent) GetSessionState added in v0.82.0

func (a *Agent) GetSessionState(ctx context.Context, sessionID string) (*SessionState, error)

GetSessionState returns the active branch and branch list for a stored session.

func (*Agent) LastExecutionTrace

func (a *Agent) LastExecutionTrace() *agents.ExecutionTrace

LastExecutionTrace returns the most recent execution trace.

func (*Agent) LastNativeTrace

func (a *Agent) LastNativeTrace() *Trace

LastNativeTrace returns the richer native-tool trace from the most recent run.

func (*Agent) RegisterTool

func (a *Agent) RegisterTool(tool core.Tool) error

RegisterTool adds a tool to the shared registry.

func (*Agent) SetArtifacts

func (a *Agent) SetArtifacts(artifacts optimize.AgentArtifacts) error

SetArtifacts updates the prompt/config backed artifacts.

func (*Agent) SwitchSessionBranch added in v0.82.0

func (a *Agent) SwitchSessionBranch(ctx context.Context, sessionID, branchID string) error

SwitchSessionBranch updates the active branch for the configured or provided session.

type Config

type Config struct {
	MaxTurns                      int
	MaxTokens                     int
	Temperature                   float64
	SystemPrompt                  string
	ToolPolicy                    string
	FinishToolText                string
	Memory                        agents.Memory
	SessionID                     string
	SessionBranchID               string
	SessionRecallLimit            int
	SessionRecallMaxChars         int
	SessionEventStore             sessionevent.SessionEventStore
	MaxConsecutiveNoCallResponses int
	ToolInterceptors              []core.ToolInterceptor
	OnEvent                       func(agents.AgentEvent)
}

Config controls the shared native tool-calling agent behavior.

type SessionState added in v0.82.0

type SessionState struct {
	Session      *sessionevent.Session
	Branches     []sessionevent.SessionBranch
	ActiveBranch *sessionevent.SessionBranch
	HeadEntry    *sessionevent.SessionEntry
}

SessionState captures the current persisted state of a session in the event store.

type TokenUsage

type TokenUsage struct {
	PromptTokens     int64 `json:"prompt_tokens"`
	CompletionTokens int64 `json:"completion_tokens"`
	TotalTokens      int64 `json:"total_tokens"`
}

TokenUsage captures aggregate token usage for one tool-calling run.

type Trace

type Trace struct {
	TaskID      string        `json:"task_id,omitempty"`
	Model       string        `json:"model"`
	Provider    string        `json:"provider"`
	Task        string        `json:"task"`
	StartedAt   time.Time     `json:"started_at"`
	Duration    time.Duration `json:"duration"`
	Completed   bool          `json:"completed"`
	FinalAnswer string        `json:"final_answer,omitempty"`
	Error       string        `json:"error,omitempty"`
	TokenUsage  TokenUsage    `json:"token_usage"`
	Steps       []TraceStep   `json:"steps"`
}

Trace captures a native tool-calling run with step-level detail.

func (*Trace) Clone

func (t *Trace) Clone() *Trace

Clone returns a deep copy of the trace.

type TraceStep

type TraceStep struct {
	Index              int               `json:"index"`
	AssistantText      string            `json:"assistant_text,omitempty"`
	ToolName           string            `json:"tool_name,omitempty"`
	Arguments          map[string]any    `json:"arguments,omitempty"`
	Observation        string            `json:"observation,omitempty"`
	ObservationDisplay string            `json:"observation_display,omitempty"`
	ObservationDetails map[string]any    `json:"observation_details,omitempty"`
	IsError            bool              `json:"is_error,omitempty"`
	Synthetic          bool              `json:"synthetic,omitempty"`
	Redacted           bool              `json:"redacted,omitempty"`
	Truncated          bool              `json:"truncated,omitempty"`
	Usage              TokenUsage        `json:"usage,omitempty"`
	Metadata           map[string]string `json:"metadata,omitempty"`
}

TraceStep captures one model/tool turn.

func (TraceStep) Clone

func (s TraceStep) Clone() TraceStep

Clone returns a deep copy of the step.

Jump to

Keyboard shortcuts

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