---
title: "agent"
---

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# agent

```go
import "github.com/goppydae/sharur/internal/agent"
```

Package agent provides the stateful agent with transcript, tools, and events.

## Index

- [Constants](<#constants>)
- [func EstimateMessageTokens\(m Message\) int](<#EstimateMessageTokens>)
- [type Agent](<#Agent>)
  - [func New\(provider llm.Provider, registry \*tools.ToolRegistry\) \*Agent](<#New>)
  - [func \(a \*Agent\) Abort\(\)](<#Agent.Abort>)
  - [func \(a \*Agent\) Compact\(ctx context.Context, keepRecentTokens int\)](<#Agent.Compact>)
  - [func \(a \*Agent\) Continue\(ctx context.Context\) error](<#Agent.Continue>)
  - [func \(a \*Agent\) EstimateContextTokens\(\) int](<#Agent.EstimateContextTokens>)
  - [func \(a \*Agent\) EventBus\(\) \*events.EventBus](<#Agent.EventBus>)
  - [func \(a \*Agent\) FollowUp\(text string, images ...Image\)](<#Agent.FollowUp>)
  - [func \(a \*Agent\) GetInfo\(\) llm.ProviderInfo](<#Agent.GetInfo>)
  - [func \(a \*Agent\) GetSession\(\) \*types.Session](<#Agent.GetSession>)
  - [func \(a \*Agent\) GetStats\(\) AgentStats](<#Agent.GetStats>)
  - [func \(a \*Agent\) Idle\(\) \<\-chan struct\{\}](<#Agent.Idle>)
  - [func \(a \*Agent\) InvokeTool\(ctx context.Context, name string, args string\) error](<#Agent.InvokeTool>)
  - [func \(a \*Agent\) IsRunning\(\) bool](<#Agent.IsRunning>)
  - [func \(a \*Agent\) LifecycleState\(\) string](<#Agent.LifecycleState>)
  - [func \(a \*Agent\) Messages\(\) \[\]Message](<#Agent.Messages>)
  - [func \(a \*Agent\) Prompt\(ctx context.Context, text string, images ...Image\) error](<#Agent.Prompt>)
  - [func \(a \*Agent\) Reset\(\)](<#Agent.Reset>)
  - [func \(a \*Agent\) ResetSession\(id string\)](<#Agent.ResetSession>)
  - [func \(a \*Agent\) Session\(\) \*session.Session](<#Agent.Session>)
  - [func \(a \*Agent\) SetCompactionConfig\(enabled bool, reserve, keepRecent int\)](<#Agent.SetCompactionConfig>)
  - [func \(a \*Agent\) SetDryRun\(dry bool\)](<#Agent.SetDryRun>)
  - [func \(a \*Agent\) SetExtensions\(exts \[\]Extension\)](<#Agent.SetExtensions>)
  - [func \(a \*Agent\) SetMaxTokens\(n int\)](<#Agent.SetMaxTokens>)
  - [func \(a \*Agent\) SetModel\(model string\)](<#Agent.SetModel>)
  - [func \(a \*Agent\) SetProvider\(provider llm.Provider\)](<#Agent.SetProvider>)
  - [func \(a \*Agent\) SetSession\(mgr \*session.Manager, sess \*session.Session\)](<#Agent.SetSession>)
  - [func \(a \*Agent\) SetSessionName\(name string\)](<#Agent.SetSessionName>)
  - [func \(a \*Agent\) SetSystemPrompt\(prompt string\)](<#Agent.SetSystemPrompt>)
  - [func \(a \*Agent\) SetThinkingLevel\(level ThinkingLevel\)](<#Agent.SetThinkingLevel>)
  - [func \(a \*Agent\) State\(\) \*AgentState](<#Agent.State>)
  - [func \(a \*Agent\) Steer\(text string, images ...Image\)](<#Agent.Steer>)
  - [func \(a \*Agent\) Subscribe\(fn func\(Event\)\) func\(\)](<#Agent.Subscribe>)
  - [func \(a \*Agent\) ToolRegistry\(\) \*tools.ToolRegistry](<#Agent.ToolRegistry>)
- [type AgentState](<#AgentState>)
- [type AgentStats](<#AgentStats>)
- [type CompactionPrep](<#CompactionPrep>)
- [type CompactionResult](<#CompactionResult>)
- [type Event](<#Event>)
- [type EventType](<#EventType>)
- [type Extension](<#Extension>)
- [type Image](<#Image>)
- [type InputAction](<#InputAction>)
- [type InputResult](<#InputResult>)
- [type LifecycleState](<#LifecycleState>)
- [type Message](<#Message>)
- [type NoopExtension](<#NoopExtension>)
  - [func \(n \*NoopExtension\) AfterCompact\(\_ context.Context, \_ int\)](<#NoopExtension.AfterCompact>)
  - [func \(n \*NoopExtension\) AfterProviderResponse\(\_ context.Context, \_ string, \_ int\)](<#NoopExtension.AfterProviderResponse>)
  - [func \(n \*NoopExtension\) AfterToolCall\(\_ context.Context, \_ \*ToolCall, result \*tools.ToolResult\) \*tools.ToolResult](<#NoopExtension.AfterToolCall>)
  - [func \(n \*NoopExtension\) AgentEnd\(\_ context.Context\)](<#NoopExtension.AgentEnd>)
  - [func \(n \*NoopExtension\) AgentStart\(\_ context.Context\)](<#NoopExtension.AgentStart>)
  - [func \(n \*NoopExtension\) BeforeCompact\(\_ context.Context, \_ CompactionPrep\) \*CompactionResult](<#NoopExtension.BeforeCompact>)
  - [func \(n \*NoopExtension\) BeforePrompt\(\_ context.Context, state \*AgentState\) \*AgentState](<#NoopExtension.BeforePrompt>)
  - [func \(n \*NoopExtension\) BeforeProviderRequest\(\_ context.Context, req \*llm.CompletionRequest\) \*llm.CompletionRequest](<#NoopExtension.BeforeProviderRequest>)
  - [func \(n \*NoopExtension\) BeforeToolCall\(\_ context.Context, \_ \*ToolCall, \_ json.RawMessage\) \(\*tools.ToolResult, bool\)](<#NoopExtension.BeforeToolCall>)
  - [func \(n \*NoopExtension\) ModifyContext\(\_ context.Context, messages \[\]types.Message\) \[\]types.Message](<#NoopExtension.ModifyContext>)
  - [func \(n \*NoopExtension\) ModifyInput\(\_ context.Context, \_ string\) InputResult](<#NoopExtension.ModifyInput>)
  - [func \(n \*NoopExtension\) ModifySystemPrompt\(prompt string\) string](<#NoopExtension.ModifySystemPrompt>)
  - [func \(n \*NoopExtension\) Name\(\) string](<#NoopExtension.Name>)
  - [func \(n \*NoopExtension\) SessionEnd\(\_ context.Context, \_ string, \_ SessionEndReason\)](<#NoopExtension.SessionEnd>)
  - [func \(n \*NoopExtension\) SessionStart\(\_ context.Context, \_ string, \_ SessionStartReason\)](<#NoopExtension.SessionStart>)
  - [func \(n \*NoopExtension\) Tools\(\) \[\]tools.Tool](<#NoopExtension.Tools>)
  - [func \(n \*NoopExtension\) TurnEnd\(\_ context.Context\)](<#NoopExtension.TurnEnd>)
  - [func \(n \*NoopExtension\) TurnStart\(\_ context.Context\)](<#NoopExtension.TurnStart>)
- [type Session](<#Session>)
- [type SessionEndReason](<#SessionEndReason>)
- [type SessionStartReason](<#SessionStartReason>)
- [type StateMachine](<#StateMachine>)
  - [func NewStateMachine\(initial LifecycleState, onTransition func\(StateTransition\)\) \*StateMachine](<#NewStateMachine>)
  - [func \(s \*StateMachine\) Current\(\) LifecycleState](<#StateMachine.Current>)
  - [func \(s \*StateMachine\) Transition\(to LifecycleState\) error](<#StateMachine.Transition>)
- [type StateTransition](<#StateTransition>)
- [type ThinkingLevel](<#ThinkingLevel>)
- [type ToolCall](<#ToolCall>)
- [type ToolInfo](<#ToolInfo>)
- [type ToolOutput](<#ToolOutput>)


## Constants

<a name="ThinkingOff"></a>

```go
const (
    ThinkingOff    = types.ThinkingOff
    ThinkingLow    = types.ThinkingLow
    ThinkingMedium = types.ThinkingMedium
    ThinkingHigh   = types.ThinkingHigh
)
```

<a name="SUMMARIZATION_PROMPT"></a>

```go
const SUMMARIZATION_PROMPT = `The messages above are a conversation to summarize. Create a structured context checkpoint summary that another LLM will use to continue the work.

Start your response with the exact string: <!-- sharur-summary -->

Then use this EXACT format:

## Goal
[What is the user trying to accomplish? Can be multiple items if the session covers different tasks.]

## Constraints & Preferences
- [Any constraints, preferences, or requirements mentioned by user]
- [Or "(none)" if none were mentioned]

## Progress
### Done
- [x] [Completed tasks/changes]

### In Progress
- [ ] [Current work]

### Blocked
- [Issues preventing progress, if any]

## Key Decisions
- **[Decision]**: [Brief rationale]

## Next Steps
1. [Ordered list of what should happen next]

## Critical Context
- [Any data, examples, or references needed to continue]
- [Or "(none)" if not applicable]

Keep each section concise. Preserve exact file paths, function names, and error messages.`
```

<a name="TURN_PREFIX_SUMMARIZATION_PROMPT"></a>

```go
const TURN_PREFIX_SUMMARIZATION_PROMPT = `This is the PREFIX of a turn that was too large to keep. The SUFFIX (recent work) is retained.

Summarize the prefix to provide context for the retained suffix:

## Original Request
[What did the user ask for in this turn?]

## Early Progress
- [Key decisions and work done in the prefix]

## Context for Suffix
- [Information needed to understand the retained recent work]

Be concise. Focus on what's needed to understand the kept suffix.`
```

<a name="UPDATE_SUMMARIZATION_PROMPT"></a>

```go
const UPDATE_SUMMARIZATION_PROMPT = `The messages above are NEW conversation messages to incorporate into the existing summary provided in <previous-summary> tags.

Start your response with the exact string: <!-- sharur-summary -->

Update the existing structured summary with new information. RULES:
- PRESERVE all existing information from the previous summary
- ADD new progress, decisions, and context from the new messages
- UPDATE the Progress section: move items from "In Progress" to "Done" when completed
- UPDATE "Next Steps" based on what was accomplished
- PRESERVE exact file paths, function names, and error messages
- If something is no longer relevant, you may remove it

Use this EXACT format:

## Goal
[Preserve existing goals, add new ones if the task expanded]

## Constraints & Preferences
- [Preserve existing, add new ones discovered]

## Progress
### Done
- [x] [Include previously done items AND newly completed items]

### In Progress
- [ ] [Current work - update based on progress]

### Blocked
- [Current blockers - remove if resolved]

## Key Decisions
- **[Decision]**: [Brief rationale] (preserve all previous, add new)

## Next Steps
1. [Update based on current state]

## Critical Context
- [Preserve important context, add new if needed]

Keep each section concise. Preserve exact file paths, function names, and error messages.`
```

<a name="EstimateMessageTokens"></a>
## func EstimateMessageTokens

```go
func EstimateMessageTokens(m Message) int
```



<a name="Agent"></a>
## type Agent

Agent owns the transcript, emits events, and executes tools.

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

<a name="New"></a>
### func New

```go
func New(provider llm.Provider, registry *tools.ToolRegistry) *Agent
```

New creates a new agent with the given provider and tools.

<a name="Agent.Abort"></a>
### func \(\*Agent\) Abort

```go
func (a *Agent) Abort()
```

Abort signals the agent to stop the current turn.

<a name="Agent.Compact"></a>
### func \(\*Agent\) Compact

```go
func (a *Agent) Compact(ctx context.Context, keepRecentTokens int)
```

Compact trims the transcript to stay within approximate token budgets. It implements a pi\-mono style summarization and file tracking strategy.

<a name="Agent.Continue"></a>
### func \(\*Agent\) Continue

```go
func (a *Agent) Continue(ctx context.Context) error
```

Continue asks the agent to continue generating.

<a name="Agent.EstimateContextTokens"></a>
### func \(\*Agent\) EstimateContextTokens

```go
func (a *Agent) EstimateContextTokens() int
```

EstimateContextTokens returns the estimated total tokens in the current context.

<a name="Agent.EventBus"></a>
### func \(\*Agent\) EventBus

```go
func (a *Agent) EventBus() *events.EventBus
```

EventBus returns the event bus.

<a name="Agent.FollowUp"></a>
### func \(\*Agent\) FollowUp

```go
func (a *Agent) FollowUp(text string, images ...Image)
```

FollowUp queues a follow\-up message to be processed after the agent finishes.

<a name="Agent.GetInfo"></a>
### func \(\*Agent\) GetInfo

```go
func (a *Agent) GetInfo() llm.ProviderInfo
```

GetInfo returns the current model's provider info.

<a name="Agent.GetSession"></a>
### func \(\*Agent\) GetSession

```go
func (a *Agent) GetSession() *types.Session
```

GetSession returns a copy of the current session types.

<a name="Agent.GetStats"></a>
### func \(\*Agent\) GetStats

```go
func (a *Agent) GetStats() AgentStats
```

GetStats returns token usage statistics from the agent's events.

<a name="Agent.Idle"></a>
### func \(\*Agent\) Idle

```go
func (a *Agent) Idle() <-chan struct{}
```

Idle returns a channel that closes when the agent is idle.

<a name="Agent.InvokeTool"></a>
### func \(\*Agent\) InvokeTool

```go
func (a *Agent) InvokeTool(ctx context.Context, name string, args string) error
```

InvokeTool manually triggers a tool call as if it came from the assistant. It executes the tool, records the result, and then starts the agent loop to allow the LLM to react to the invocation.

<a name="Agent.IsRunning"></a>
### func \(\*Agent\) IsRunning

```go
func (a *Agent) IsRunning() bool
```

IsRunning reports whether the agent is currently processing.

<a name="Agent.LifecycleState"></a>
### func \(\*Agent\) LifecycleState

```go
func (a *Agent) LifecycleState() string
```

LifecycleState returns the current lifecycle state as a string.

<a name="Agent.Messages"></a>
### func \(\*Agent\) Messages

```go
func (a *Agent) Messages() []Message
```

Messages returns a copy of the conversation messages.

<a name="Agent.Prompt"></a>
### func \(\*Agent\) Prompt

```go
func (a *Agent) Prompt(ctx context.Context, text string, images ...Image) error
```

Prompt sends a user message and runs the agent loop until idle.

<a name="Agent.Reset"></a>
### func \(\*Agent\) Reset

```go
func (a *Agent) Reset()
```

Reset clears the conversation history and queues.

<a name="Agent.ResetSession"></a>
### func \(\*Agent\) ResetSession

```go
func (a *Agent) ResetSession(id string)
```

ResetSession clears messages, queues and creates a fresh session ID.

<a name="Agent.Session"></a>
### func \(\*Agent\) Session

```go
func (a *Agent) Session() *session.Session
```

Session returns the current session object.

<a name="Agent.SetCompactionConfig"></a>
### func \(\*Agent\) SetCompactionConfig

```go
func (a *Agent) SetCompactionConfig(enabled bool, reserve, keepRecent int)
```

SetCompactionConfig updates the compaction settings.

<a name="Agent.SetDryRun"></a>
### func \(\*Agent\) SetDryRun

```go
func (a *Agent) SetDryRun(dry bool)
```

SetDryRun sets the agent's dry\-run mode.

<a name="Agent.SetExtensions"></a>
### func \(\*Agent\) SetExtensions

```go
func (a *Agent) SetExtensions(exts []Extension)
```

SetExtensions sets the active extensions for the agent.

<a name="Agent.SetMaxTokens"></a>
### func \(\*Agent\) SetMaxTokens

```go
func (a *Agent) SetMaxTokens(n int)
```

SetMaxTokens sets the maximum tokens for LLM responses.

<a name="Agent.SetModel"></a>
### func \(\*Agent\) SetModel

```go
func (a *Agent) SetModel(model string)
```

SetModel sets the model name and records it in the session if manager is present.

<a name="Agent.SetProvider"></a>
### func \(\*Agent\) SetProvider

```go
func (a *Agent) SetProvider(provider llm.Provider)
```

SetProvider sets the LLM provider and records it in the session if manager is present.

<a name="Agent.SetSession"></a>
### func \(\*Agent\) SetSession

```go
func (a *Agent) SetSession(mgr *session.Manager, sess *session.Session)
```

SetSession attaches a session manager and session to the agent.

<a name="Agent.SetSessionName"></a>
### func \(\*Agent\) SetSessionName

```go
func (a *Agent) SetSessionName(name string)
```

SetSessionName sets a human\-readable name for the current session.

<a name="Agent.SetSystemPrompt"></a>
### func \(\*Agent\) SetSystemPrompt

```go
func (a *Agent) SetSystemPrompt(prompt string)
```

SetSystemPrompt updates the system prompt.

<a name="Agent.SetThinkingLevel"></a>
### func \(\*Agent\) SetThinkingLevel

```go
func (a *Agent) SetThinkingLevel(level ThinkingLevel)
```

SetThinkingLevel sets the thinking level and records it in the session if manager is present.

<a name="Agent.State"></a>
### func \(\*Agent\) State

```go
func (a *Agent) State() *AgentState
```

State returns a copy of the current agent state.

<a name="Agent.Steer"></a>
### func \(\*Agent\) Steer

```go
func (a *Agent) Steer(text string, images ...Image)
```

Steer queues a steering message to be injected as soon as the current tool execution finishes.

<a name="Agent.Subscribe"></a>
### func \(\*Agent\) Subscribe

```go
func (a *Agent) Subscribe(fn func(Event)) func()
```

Subscribe registers an event listener and returns an unsubscribe function.

<a name="Agent.ToolRegistry"></a>
### func \(\*Agent\) ToolRegistry

```go
func (a *Agent) ToolRegistry() *tools.ToolRegistry
```

ToolRegistry returns the tool registry.

<a name="AgentState"></a>
## type AgentState

AgentState holds the full state of an agent instance.

```go
type AgentState struct {
    Session       Session       `json:"session"`
    SystemPrompt  string        `json:"systemPrompt"`
    Messages      []Message     `json:"messages"`
    SteerQueue    []Message     `json:"steerQueue,omitempty"`
    FollowUpQueue []Message     `json:"followUpQueue,omitempty"`
    Tools         []ToolInfo    `json:"tools,omitempty"`
    Model         string        `json:"model"`
    Provider      string        `json:"provider"`
    Thinking      ThinkingLevel `json:"thinkingLevel"`
    MaxTokens     int           `json:"maxTokens,omitempty"`
    Temperature   float64       `json:"temperature,omitempty"`
    DryRun        bool          `json:"dryRun,omitempty"`
    Compaction    struct {
        Enabled          bool `json:"enabled"`
        ReserveTokens    int  `json:"reserveTokens"`
        KeepRecentTokens int  `json:"keepRecentTokens"`
    }   `json:"compaction"`
    LatestCompaction *types.CompactionState `json:"latestCompaction,omitempty"`
}
```

<a name="AgentStats"></a>
## type AgentStats

AgentStats holds session statistics.

```go
type AgentStats struct {
    SessionID      string
    ParentID       string
    SessionFile    string
    Name           string
    CreatedAt      time.Time
    UpdatedAt      time.Time
    Model          string
    Provider       string
    Thinking       string
    UserMessages   int
    AssistantMsgs  int
    ToolCalls      int
    ToolResults    int
    TotalMessages  int
    InputTokens    int
    OutputTokens   int
    CacheRead      int
    CacheWrite     int
    TotalTokens    int
    ContextTokens  int
    ContextWindow  int
    Cost           float64
    QueuedSteer    int
    QueuedFollowUp int
}
```

<a name="CompactionPrep"></a>
## type CompactionPrep

CompactionPrep describes the state passed to BeforeCompact.

```go
type CompactionPrep struct {
    MessageCount    int
    EstimatedTokens int
    PreviousSummary string
}
```

<a name="CompactionResult"></a>
## type CompactionResult

CompactionResult can be returned by BeforeCompact to provide a custom summary and skip the default LLM\-based summarization.

```go
type CompactionResult struct {
    Summary          string
    FirstKeptEntryID string
}
```

<a name="Event"></a>
## type Event

Event represents an agent lifecycle event.

```go
type Event struct {
    Type     EventType
    Content  string
    ToolCall *ToolCall
    Usage    *llm.Usage
    Error    error
    // ToolOutput stores the result content of a tool execution.
    // Emitted when type is EventToolOutput.
    ToolOutput *ToolOutput
    // StateChange holds details of a lifecycle state transition.
    // Emitted when type is EventStateChange.
    StateChange *StateTransition
    // Value stores a numeric value (e.g. token count).
    // Emitted when type is EventTokens.
    Value int64
}
```

<a name="EventType"></a>
## type EventType

EventType identifies the kind of agent event.

```go
type EventType string
```

<a name="EventAgentStart"></a>

```go
const (
    EventAgentStart    EventType = "agent_start"
    EventTurnStart     EventType = "turn_start"
    EventMessageStart  EventType = "message_start"
    EventTextDelta     EventType = "text_delta"
    EventThinkingDelta EventType = "thinking_delta"
    EventToolCall      EventType = "tool_call"
    EventToolDelta     EventType = "tool_delta"
    EventToolOutput    EventType = "tool_output"
    EventMessageEnd    EventType = "message_end"
    EventAgentEnd      EventType = "agent_end"
    EventError         EventType = "error"
    EventAbort         EventType = "abort"
    EventQueueUpdate   EventType = "queue_update"
    EventCompactStart  EventType = "compact_start"
    EventCompactEnd    EventType = "compact_end"
    EventStateChange   EventType = "state_change"
    EventTokens        EventType = "tokens"
    EventHeartbeat     EventType = "heartbeat"
)
```

<a name="Extension"></a>
## type Extension

Extension is the unified interface for all extensions \(gRPC plugins, Markdown Skills, etc.\)

```go
type Extension interface {
    // Name returns the extension's unique identifier.
    Name() string

    // Tools returns additional tools to register with the agent.
    Tools() []tools.Tool

    // BeforePrompt is called before each LLM request.
    // Return a modified state to change the request.
    BeforePrompt(ctx context.Context, state *AgentState) *AgentState

    // BeforeToolCall is called before each tool execution.
    // Return (result, true) to intercept and prevent the tool from running.
    // Return (nil, false) to allow normal execution.
    BeforeToolCall(ctx context.Context, call *ToolCall, args json.RawMessage) (*tools.ToolResult, bool)

    // AfterToolCall is called after each tool call completes.
    // Return a modified result to change the outcome.
    AfterToolCall(ctx context.Context, call *ToolCall, result *tools.ToolResult) *tools.ToolResult

    // ModifySystemPrompt is called to augment the system prompt.
    ModifySystemPrompt(prompt string) string

    // SessionStart is called when a session is attached or the first prompt begins.
    SessionStart(ctx context.Context, sessionID string, reason SessionStartReason)

    // SessionEnd is called when a session is reset or the agent is torn down.
    SessionEnd(ctx context.Context, sessionID string, reason SessionEndReason)

    // AgentStart is called when the agent begins processing a user prompt.
    AgentStart(ctx context.Context)

    // AgentEnd is called when the agent loop finishes (success, error, or abort).
    AgentEnd(ctx context.Context)

    // TurnStart is called at the start of each LLM request turn.
    TurnStart(ctx context.Context)

    // TurnEnd is called after each turn's tool calls have been processed.
    TurnEnd(ctx context.Context)

    // ModifyInput is called with raw user input before it is added to the transcript.
    // Return InputHandled to consume the message without further processing.
    // Return InputTransform to replace the text.
    // Return InputContinue (or zero value) to proceed unchanged.
    ModifyInput(ctx context.Context, text string) InputResult

    // ModifyContext is called with the message slice just before building each LLM
    // request. The returned slice replaces what is sent to the LLM (not the stored
    // transcript). Extensions are chained; each receives the previous result.
    ModifyContext(ctx context.Context, messages []types.Message) []types.Message

    // BeforeProviderRequest is called with the assembled CompletionRequest before
    // it is sent to the LLM provider. Return a modified copy to alter the request.
    BeforeProviderRequest(ctx context.Context, req *llm.CompletionRequest) *llm.CompletionRequest

    // AfterProviderResponse is called after the LLM stream is fully consumed.
    AfterProviderResponse(ctx context.Context, content string, numToolCalls int)

    // BeforeCompact is called before the compaction summarization LLM call.
    // Return a non-nil *CompactionResult to provide a custom summary and skip the
    // default LLM-based summarization entirely.
    BeforeCompact(ctx context.Context, prep CompactionPrep) *CompactionResult

    // AfterCompact is called after compaction completes.
    AfterCompact(ctx context.Context, freedTokens int)
}
```

<a name="Image"></a>
## type Image

Image is an alias for types.Image.

```go
type Image = types.Image
```

<a name="InputAction"></a>
## type InputAction

InputAction controls how ModifyInput's result is applied.

```go
type InputAction string
```

<a name="InputContinue"></a>

```go
const (
    // InputContinue passes the original text through unchanged.
    InputContinue InputAction = "continue"
    // InputTransform replaces the user text with InputResult.Text.
    InputTransform InputAction = "transform"
    // InputHandled marks the input as consumed; the message is not appended to the transcript.
    InputHandled InputAction = "handled"
)
```

<a name="InputResult"></a>
## type InputResult

InputResult is returned by ModifyInput to describe how to process the user input.

```go
type InputResult struct {
    Action InputAction
    Text   string
}
```

<a name="LifecycleState"></a>
## type LifecycleState

LifecycleState identifies the current operational state of the agent.

```go
type LifecycleState string
```

<a name="StateIdle"></a>

```go
const (
    StateIdle       LifecycleState = "idle"
    StateThinking   LifecycleState = "thinking"
    StateExecuting  LifecycleState = "executing"
    StateCompacting LifecycleState = "compacting"
    StateAborting   LifecycleState = "aborting"
    StateError      LifecycleState = "error"
)
```

<a name="Message"></a>
## type Message

Message is an alias for types.Message.

```go
type Message = types.Message
```

<a name="NoopExtension"></a>
## type NoopExtension

NoopExtension is an extension that does nothing — useful as a base embed.

```go
type NoopExtension struct {
    NameStr string
}
```

<a name="NoopExtension.AfterCompact"></a>
### func \(\*NoopExtension\) AfterCompact

```go
func (n *NoopExtension) AfterCompact(_ context.Context, _ int)
```



<a name="NoopExtension.AfterProviderResponse"></a>
### func \(\*NoopExtension\) AfterProviderResponse

```go
func (n *NoopExtension) AfterProviderResponse(_ context.Context, _ string, _ int)
```



<a name="NoopExtension.AfterToolCall"></a>
### func \(\*NoopExtension\) AfterToolCall

```go
func (n *NoopExtension) AfterToolCall(_ context.Context, _ *ToolCall, result *tools.ToolResult) *tools.ToolResult
```



<a name="NoopExtension.AgentEnd"></a>
### func \(\*NoopExtension\) AgentEnd

```go
func (n *NoopExtension) AgentEnd(_ context.Context)
```



<a name="NoopExtension.AgentStart"></a>
### func \(\*NoopExtension\) AgentStart

```go
func (n *NoopExtension) AgentStart(_ context.Context)
```



<a name="NoopExtension.BeforeCompact"></a>
### func \(\*NoopExtension\) BeforeCompact

```go
func (n *NoopExtension) BeforeCompact(_ context.Context, _ CompactionPrep) *CompactionResult
```



<a name="NoopExtension.BeforePrompt"></a>
### func \(\*NoopExtension\) BeforePrompt

```go
func (n *NoopExtension) BeforePrompt(_ context.Context, state *AgentState) *AgentState
```



<a name="NoopExtension.BeforeProviderRequest"></a>
### func \(\*NoopExtension\) BeforeProviderRequest

```go
func (n *NoopExtension) BeforeProviderRequest(_ context.Context, req *llm.CompletionRequest) *llm.CompletionRequest
```



<a name="NoopExtension.BeforeToolCall"></a>
### func \(\*NoopExtension\) BeforeToolCall

```go
func (n *NoopExtension) BeforeToolCall(_ context.Context, _ *ToolCall, _ json.RawMessage) (*tools.ToolResult, bool)
```



<a name="NoopExtension.ModifyContext"></a>
### func \(\*NoopExtension\) ModifyContext

```go
func (n *NoopExtension) ModifyContext(_ context.Context, messages []types.Message) []types.Message
```



<a name="NoopExtension.ModifyInput"></a>
### func \(\*NoopExtension\) ModifyInput

```go
func (n *NoopExtension) ModifyInput(_ context.Context, _ string) InputResult
```



<a name="NoopExtension.ModifySystemPrompt"></a>
### func \(\*NoopExtension\) ModifySystemPrompt

```go
func (n *NoopExtension) ModifySystemPrompt(prompt string) string
```



<a name="NoopExtension.Name"></a>
### func \(\*NoopExtension\) Name

```go
func (n *NoopExtension) Name() string
```



<a name="NoopExtension.SessionEnd"></a>
### func \(\*NoopExtension\) SessionEnd

```go
func (n *NoopExtension) SessionEnd(_ context.Context, _ string, _ SessionEndReason)
```



<a name="NoopExtension.SessionStart"></a>
### func \(\*NoopExtension\) SessionStart

```go
func (n *NoopExtension) SessionStart(_ context.Context, _ string, _ SessionStartReason)
```



<a name="NoopExtension.Tools"></a>
### func \(\*NoopExtension\) Tools

```go
func (n *NoopExtension) Tools() []tools.Tool
```



<a name="NoopExtension.TurnEnd"></a>
### func \(\*NoopExtension\) TurnEnd

```go
func (n *NoopExtension) TurnEnd(_ context.Context)
```



<a name="NoopExtension.TurnStart"></a>
### func \(\*NoopExtension\) TurnStart

```go
func (n *NoopExtension) TurnStart(_ context.Context)
```



<a name="Session"></a>
## type Session

Session is an alias for types.Session.

```go
type Session = types.Session
```

<a name="SessionEndReason"></a>
## type SessionEndReason

SessionEndReason identifies why a session is ending.

```go
type SessionEndReason string
```

<a name="SessionEndReset"></a>

```go
const (
    SessionEndReset SessionEndReason = "reset"
)
```

<a name="SessionStartReason"></a>
## type SessionStartReason

SessionStartReason identifies why a session is starting.

```go
type SessionStartReason string
```

<a name="SessionStartNew"></a>

```go
const (
    SessionStartNew    SessionStartReason = "new"
    SessionStartResume SessionStartReason = "resume"
)
```

<a name="StateMachine"></a>
## type StateMachine

StateMachine manages agent states and transitions.

```go
type StateMachine struct {
    // contains filtered or unexported fields
}
```

<a name="NewStateMachine"></a>
### func NewStateMachine

```go
func NewStateMachine(initial LifecycleState, onTransition func(StateTransition)) *StateMachine
```

NewStateMachine creates a new state machine.

<a name="StateMachine.Current"></a>
### func \(\*StateMachine\) Current

```go
func (s *StateMachine) Current() LifecycleState
```

Current returns the current lifecycle state.

<a name="StateMachine.Transition"></a>
### func \(\*StateMachine\) Transition

```go
func (s *StateMachine) Transition(to LifecycleState) error
```

Transition moves the state machine to a new state.

<a name="StateTransition"></a>
## type StateTransition

StateTransition represents a transition between two states.

```go
type StateTransition struct {
    From LifecycleState
    To   LifecycleState
}
```

<a name="ThinkingLevel"></a>
## type ThinkingLevel

ThinkingLevel is an alias for types.ThinkingLevel.

```go
type ThinkingLevel = types.ThinkingLevel
```

<a name="ToolCall"></a>
## type ToolCall

ToolCall is an alias for types.ToolCall.

```go
type ToolCall = types.ToolCall
```

<a name="ToolInfo"></a>
## type ToolInfo

ToolInfo is an alias for types.ToolInfo.

```go
type ToolInfo = types.ToolInfo
```

<a name="ToolOutput"></a>
## type ToolOutput

ToolOutput is an alias for types.ToolOutput.

```go
type ToolOutput = types.ToolOutput
```

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
