Documentation
¶
Index ¶
- func IsEphemeralAgentEvent(ctx context.Context) bool
- func MarshalAgentEvent(event AgentEvent) ([]byte, error)
- func ToolExecutionModel(ctx context.Context) *ai.Model
- func WithToolExecutionModel(ctx context.Context, model *ai.Model) context.Context
- type AfterToolCallContext
- type AfterToolCallFunc
- type AfterToolCallResult
- type Agent
- func (agent *Agent) Abort()
- func (agent *Agent) AppendMessage(message AgentMessage)
- func (agent *Agent) ClearAllQueues()
- func (agent *Agent) ClearFollowUpQueue()
- func (agent *Agent) ClearSteeringQueue()
- func (agent *Agent) Continue(ctx context.Context) error
- func (agent *Agent) DisplayState() AgentDisplayState
- func (agent *Agent) FollowUp(message AgentMessage)
- func (agent *Agent) FollowUpMode() QueueMode
- func (agent *Agent) HasQueuedMessages() bool
- func (agent *Agent) IsIdle() bool
- func (agent *Agent) Observe(initialize func(AgentState), event func(AgentEvent)) func()
- func (agent *Agent) PeekQueuedMessages() AgentMessages
- func (agent *Agent) Prompt(ctx context.Context, input any, images ...*ai.ImageContent) error
- func (agent *Agent) ReplaceLastMessage(replacement AgentMessage) bool
- func (agent *Agent) Reset()
- func (agent *Agent) SessionLoopExclusive() bool
- func (agent *Agent) SetFollowUpMode(mode QueueMode)
- func (agent *Agent) SetMessages(messages AgentMessages)
- func (agent *Agent) SetModel(model *ai.Model)
- func (agent *Agent) SetProviderHooks(payload ai.PayloadHook, headers ai.HeadersHook, response ai.ResponseHook, ...)
- func (agent *Agent) SetRequestResolvers(apiKey GetAPIKeyFunc, auth GetRequestAuthFunc, headers GetModelHeadersFunc)
- func (agent *Agent) SetRequestSystemPromptOverride(prompt *string)
- func (agent *Agent) SetSessionLoop(claims func(*ai.Model) bool, loop SessionLoop)
- func (agent *Agent) SetSteeringMode(mode QueueMode)
- func (agent *Agent) SetStreamFn(stream StreamFn)
- func (agent *Agent) SetStreamSessionID(sessionID string)
- func (agent *Agent) SetThinkingLevel(level ThinkingLevel)
- func (agent *Agent) SetToolCallHooks(before BeforeToolCallFunc, after AfterToolCallFunc)
- func (agent *Agent) SetTools(tools []AgentTool)
- func (agent *Agent) SetTransformContext(transform TransformContextFunc)
- func (agent *Agent) SetTransport(transport ai.Transport)
- func (agent *Agent) Signal() context.Context
- func (agent *Agent) State() AgentState
- func (agent *Agent) Steer(message AgentMessage)
- func (agent *Agent) SteeringMode() QueueMode
- func (agent *Agent) StreamFn() StreamFn
- func (agent *Agent) Subscribe(listener EventSink) func()
- func (agent *Agent) SwapFinishTurn(hook FinishTurnFunc) FinishTurnFunc
- func (agent *Agent) SwapPrepareNextTurnContext(hook PrepareNextTurnFunc) PrepareNextTurnFunc
- func (agent *Agent) SwapPrepareRequest(hook PrepareRequestFunc) PrepareRequestFunc
- func (agent *Agent) ToolExecution() ToolExecutionMode
- func (agent *Agent) UsesSessionLoop() bool
- func (agent *Agent) WaitForIdle(ctx context.Context) error
- type AgentContext
- type AgentDisplayState
- type AgentEndEvent
- type AgentEvent
- type AgentEventType
- type AgentLoopConfig
- type AgentLoopTurnUpdate
- type AgentMessage
- type AgentMessages
- type AgentOption
- func WithAPIKeyResolver(resolve GetAPIKeyFunc) AgentOption
- func WithAfterToolCall(hook AfterToolCallFunc) AgentOption
- func WithBeforeToolCall(hook BeforeToolCallFunc) AgentOption
- func WithClock(now func() int64) AgentOption
- func WithConvertToLLM(convert ConvertToLLMFunc) AgentOption
- func WithFinishTurn(hook FinishTurnFunc) AgentOption
- func WithFollowUpMode(mode QueueMode) AgentOption
- func WithGetSteeringMessages(getter GetQueuedMessagesFunc) AgentOption
- func WithInitialState(state AgentState) AgentOption
- func WithModelHeadersResolver(resolve GetModelHeadersFunc) AgentOption
- func WithPrepareNextTurnContext(hook PrepareNextTurnFunc) AgentOption
- func WithPrepareRequest(hook PrepareRequestFunc) AgentOption
- func WithRequestAuthResolver(resolve GetRequestAuthFunc) AgentOption
- func WithSessionLoop(loop SessionLoop) AgentOption
- func WithSimpleStreamOptions(streamOptions ai.SimpleStreamOptions) AgentOption
- func WithSteeringMode(mode QueueMode) AgentOption
- func WithToolExecution(mode ToolExecutionMode) AgentOption
- type AgentStartEvent
- type AgentState
- type AgentTool
- type AgentToolCallOutcome
- type AgentToolFunc
- type AgentToolResult
- type AgentToolSpec
- type AgentToolUpdateCallback
- type BeforeToolCallContext
- type BeforeToolCallFunc
- type BeforeToolCallResult
- type ConvertToLLMFunc
- type EventSink
- type FinishTurnFunc
- type GetAPIKeyFunc
- type GetModelHeadersFunc
- type GetQueuedMessagesFunc
- type GetRequestAuthFunc
- type MessageEndEvent
- type MessageStartEvent
- type MessageUpdateEvent
- type ParallelExecutionPreparer
- type PrepareArgumentsFunc
- type PrepareNextTurnContext
- type PrepareNextTurnFunc
- type PrepareRequestContext
- type PrepareRequestFunc
- type QueueMode
- type RequestAuth
- type RunToolCallOptions
- type SessionLoop
- type StreamFn
- type ThinkingLevel
- type ToolExecuteFunc
- type ToolExecutionEndEvent
- type ToolExecutionMode
- type ToolExecutionStartEvent
- type ToolExecutionUpdateEvent
- type TransformContextFunc
- type TurnAction
- type TurnContext
- type TurnEndEvent
- type TurnStartEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEphemeralAgentEvent ¶
IsEphemeralAgentEvent reports whether a terminal event closes recovery scaffolding rather than durable conversation history. A streamed response can emit start/update events before its malformed finish reason is known, so transcript stores must make their persistence decision on MessageEnd.
func MarshalAgentEvent ¶
func MarshalAgentEvent(event AgentEvent) ([]byte, error)
func ToolExecutionModel ¶
ToolExecutionModel returns the request model attached by the loop. Tools use it for behavior that depends on model capabilities, matching upstream's per-invocation tool context rather than startup-time configuration.
Types ¶
type AfterToolCallContext ¶
type AfterToolCallContext struct {
AssistantMessage *ai.AssistantMessage
ToolCall *ai.ToolCall
Args any
Result AgentToolResult
IsError bool
Context *AgentContext
}
type AfterToolCallFunc ¶
type AfterToolCallFunc func(context.Context, AfterToolCallContext) (*AfterToolCallResult, error)
AfterToolCallFunc may be invoked concurrently for parallel tool calls.
type AfterToolCallResult ¶
type AfterToolCallResult struct {
Content ai.ToolResultContent
Details any
DetailsSet bool
// StructuredContent replaces the result's; when Content is replaced
// without it, the old structured content is dropped as no longer matching.
StructuredContent any
IsError *bool
Usage *ai.Usage
Terminate *bool
}
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the stateful wrapper around RunLoop and RunLoopContinue.
func NewAgent ¶
func NewAgent(stream StreamFn, option ...AgentOption) *Agent
func (*Agent) AppendMessage ¶
func (agent *Agent) AppendMessage(message AgentMessage)
func (*Agent) ClearAllQueues ¶
func (agent *Agent) ClearAllQueues()
func (*Agent) ClearFollowUpQueue ¶
func (agent *Agent) ClearFollowUpQueue()
func (*Agent) ClearSteeringQueue ¶
func (agent *Agent) ClearSteeringQueue()
func (*Agent) DisplayState ¶
func (agent *Agent) DisplayState() AgentDisplayState
func (*Agent) FollowUp ¶
func (agent *Agent) FollowUp(message AgentMessage)
func (*Agent) FollowUpMode ¶
func (*Agent) HasQueuedMessages ¶
func (*Agent) Observe ¶ added in v0.8.0
func (agent *Agent) Observe(initialize func(AgentState), event func(AgentEvent)) func()
func (*Agent) PeekQueuedMessages ¶ added in v0.14.0
func (agent *Agent) PeekQueuedMessages() AgentMessages
PeekQueuedMessages returns the batch the next turn would take, steering first and following the queue modes, without consuming it.
func (*Agent) Prompt ¶
Prompt starts a run from a string, one AgentMessage, or AgentMessages. String prompts accept optional images and are normalized to upstream content blocks.
func (*Agent) ReplaceLastMessage ¶
func (agent *Agent) ReplaceLastMessage(replacement AgentMessage) bool
func (*Agent) SessionLoopExclusive ¶ added in v0.12.0
SessionLoopExclusive reports a session loop that runs every model, which a model on Orb's own loop cannot join.
func (*Agent) SetFollowUpMode ¶
func (*Agent) SetMessages ¶
func (agent *Agent) SetMessages(messages AgentMessages)
func (*Agent) SetProviderHooks ¶
func (agent *Agent) SetProviderHooks(payload ai.PayloadHook, headers ai.HeadersHook, response ai.ResponseHook, stream ai.ProviderStreamEventHook)
func (*Agent) SetRequestResolvers ¶
func (agent *Agent) SetRequestResolvers(apiKey GetAPIKeyFunc, auth GetRequestAuthFunc, headers GetModelHeadersFunc)
func (*Agent) SetRequestSystemPromptOverride ¶ added in v0.7.0
SetRequestSystemPromptOverride projects an exact provider-facing prompt for the next run without changing transcript persistence.
func (*Agent) SetSessionLoop ¶ added in v0.12.0
func (agent *Agent) SetSessionLoop(claims func(*ai.Model) bool, loop SessionLoop)
SetSessionLoop hands the runs of the models claims accepts to loop; other models keep Orb's own loop, so one conversation can move between them.
func (*Agent) SetSteeringMode ¶
func (*Agent) SetStreamFn ¶
func (*Agent) SetStreamSessionID ¶
SetStreamSessionID sets the per-request session id providers use for affinity and prompt-cache keys (upstream Agent's constructor sessionId).
func (*Agent) SetThinkingLevel ¶
func (agent *Agent) SetThinkingLevel(level ThinkingLevel)
func (*Agent) SetToolCallHooks ¶
func (agent *Agent) SetToolCallHooks(before BeforeToolCallFunc, after AfterToolCallFunc)
func (*Agent) SetTransformContext ¶
func (agent *Agent) SetTransformContext(transform TransformContextFunc)
func (*Agent) SetTransport ¶
func (*Agent) Signal ¶
Signal returns the active run context, matching upstream's abort signal exposure to extensions. It is nil while the agent is idle.
func (*Agent) State ¶
func (agent *Agent) State() AgentState
State is a copy of the agent's state. SystemPrompt is replayed from the transcript's system messages; to change it, append a system message.
func (*Agent) Steer ¶
func (agent *Agent) Steer(message AgentMessage)
func (*Agent) SteeringMode ¶
func (*Agent) Subscribe ¶
Subscribe adds a listener and returns its unsubscribe func. Listeners are awaited in subscription order for each event; overlapping upstream events may invoke the same listener concurrently.
func (*Agent) SwapFinishTurn ¶ added in v0.14.0
func (agent *Agent) SwapFinishTurn(hook FinishTurnFunc) FinishTurnFunc
SwapFinishTurn replaces the finish-turn hook and returns its predecessor.
func (*Agent) SwapPrepareNextTurnContext ¶ added in v0.6.0
func (agent *Agent) SwapPrepareNextTurnContext(hook PrepareNextTurnFunc) PrepareNextTurnFunc
SwapPrepareNextTurnContext replaces the next-turn hook and returns its predecessor.
func (*Agent) SwapPrepareRequest ¶ added in v0.14.0
func (agent *Agent) SwapPrepareRequest(hook PrepareRequestFunc) PrepareRequestFunc
SwapPrepareRequest replaces the before-request hook and returns its predecessor.
func (*Agent) ToolExecution ¶ added in v0.14.0
func (agent *Agent) ToolExecution() ToolExecutionMode
ToolExecution is how the agent runs a response's tool calls.
func (*Agent) UsesSessionLoop ¶ added in v0.9.0
UsesSessionLoop reports whether the current model's runs, and so their execution policies, belong to an external session.
type AgentContext ¶
type AgentContext struct {
SystemPrompt string
Messages AgentMessages
Tools []AgentTool
}
type AgentDisplayState ¶
type AgentDisplayState struct {
HasModel bool
ModelID string
Provider ai.ProviderID
ContextWindow float64
Reasoning bool
ThinkingLevel ThinkingLevel
}
type AgentEndEvent ¶
type AgentEndEvent struct {
Messages AgentMessages
}
func (AgentEndEvent) MarshalJSON ¶
func (event AgentEndEvent) MarshalJSON() ([]byte, error)
func (AgentEndEvent) Type ¶
func (AgentEndEvent) Type() AgentEventType
type AgentEvent ¶
type AgentEvent interface {
Type() AgentEventType
// contains filtered or unexported methods
}
type AgentEventType ¶
type AgentEventType string
const ( EventAgentStart AgentEventType = "agent_start" EventAgentEnd AgentEventType = "agent_end" EventTurnStart AgentEventType = "turn_start" EventTurnEnd AgentEventType = "turn_end" EventMessageStart AgentEventType = "message_start" EventMessageUpdate AgentEventType = "message_update" EventMessageEnd AgentEventType = "message_end" EventToolExecutionStart AgentEventType = "tool_execution_start" EventToolExecutionUpdate AgentEventType = "tool_execution_update" EventToolExecutionEnd AgentEventType = "tool_execution_end" )
type AgentLoopConfig ¶
type AgentLoopConfig struct {
ai.SimpleStreamOptions
Model *ai.Model
ConvertToLLM ConvertToLLMFunc
TransformContext TransformContextFunc
GetAPIKey GetAPIKeyFunc
GetRequestAuth GetRequestAuthFunc
GetModelHeaders GetModelHeadersFunc
FinishTurn FinishTurnFunc
PrepareRequest PrepareRequestFunc
PrepareNextTurn PrepareNextTurnFunc
GetSteeringMessages GetQueuedMessagesFunc
GetFollowUpMessages GetQueuedMessagesFunc
ToolExecution ToolExecutionMode
BeforeToolCall BeforeToolCallFunc
AfterToolCall AfterToolCallFunc
Now func() int64
}
type AgentLoopTurnUpdate ¶
type AgentLoopTurnUpdate struct {
Context *AgentContext
Model *ai.Model
ThinkingLevel *ThinkingLevel
}
type AgentMessage ¶
type AgentMessage = any
AgentMessage is an LLM message or an application-defined message. Standard messages are ai.Message values; any JSON-marshalable value may be carried so applications retain upstream's custom-message extension point.
type AgentMessages ¶
type AgentMessages []AgentMessage
func RunLoop ¶
func RunLoop( ctx context.Context, prompts AgentMessages, loopContext AgentContext, config AgentLoopConfig, sink EventSink, streamFn StreamFn, ) (AgentMessages, error)
RunLoop starts a loop with prompt messages and returns only messages created by this invocation. The caller-owned context is copied before it is changed.
func RunLoopContinue ¶
func RunLoopContinue( ctx context.Context, loopContext *AgentContext, config AgentLoopConfig, sink EventSink, streamFn StreamFn, ) (AgentMessages, error)
RunLoopContinue resumes a non-assistant transcript without adding a prompt.
type AgentOption ¶
type AgentOption func(*agentOptions)
func WithAPIKeyResolver ¶
func WithAPIKeyResolver(resolve GetAPIKeyFunc) AgentOption
func WithAfterToolCall ¶
func WithAfterToolCall(hook AfterToolCallFunc) AgentOption
func WithBeforeToolCall ¶
func WithBeforeToolCall(hook BeforeToolCallFunc) AgentOption
func WithClock ¶
func WithClock(now func() int64) AgentOption
WithClock supplies JavaScript Date.now-compatible milliseconds. It is useful for deterministic fixture runs and applications with an injected clock.
func WithConvertToLLM ¶
func WithConvertToLLM(convert ConvertToLLMFunc) AgentOption
func WithFinishTurn ¶ added in v0.14.0
func WithFinishTurn(hook FinishTurnFunc) AgentOption
func WithFollowUpMode ¶
func WithFollowUpMode(mode QueueMode) AgentOption
func WithGetSteeringMessages ¶
func WithGetSteeringMessages(getter GetQueuedMessagesFunc) AgentOption
func WithInitialState ¶
func WithInitialState(state AgentState) AgentOption
func WithModelHeadersResolver ¶
func WithModelHeadersResolver(resolve GetModelHeadersFunc) AgentOption
func WithPrepareNextTurnContext ¶
func WithPrepareNextTurnContext(hook PrepareNextTurnFunc) AgentOption
func WithPrepareRequest ¶ added in v0.14.0
func WithPrepareRequest(hook PrepareRequestFunc) AgentOption
func WithRequestAuthResolver ¶
func WithRequestAuthResolver(resolve GetRequestAuthFunc) AgentOption
func WithSessionLoop ¶ added in v0.9.0
func WithSessionLoop(loop SessionLoop) AgentOption
func WithSimpleStreamOptions ¶
func WithSimpleStreamOptions(streamOptions ai.SimpleStreamOptions) AgentOption
func WithSteeringMode ¶
func WithSteeringMode(mode QueueMode) AgentOption
func WithToolExecution ¶
func WithToolExecution(mode ToolExecutionMode) AgentOption
type AgentStartEvent ¶
type AgentStartEvent struct{}
func (AgentStartEvent) MarshalJSON ¶
func (AgentStartEvent) MarshalJSON() ([]byte, error)
func (AgentStartEvent) Type ¶
func (AgentStartEvent) Type() AgentEventType
type AgentState ¶
type AgentState struct {
SystemPrompt string
Model *ai.Model
ThinkingLevel ThinkingLevel
Tools []AgentTool
Messages AgentMessages
IsStreaming bool
StreamingMessage AgentMessage
PendingToolCalls map[string]struct{}
ErrorMessage *string
}
type AgentTool ¶
type AgentTool interface {
Spec() AgentToolSpec
Execute(context.Context, string, any, AgentToolUpdateCallback) (AgentToolResult, error)
}
AgentTool is the execution seam shared by built-in, extension, and MCP tools. Spec returns immutable call metadata for a single loop decision.
type AgentToolCallOutcome ¶ added in v0.14.0
type AgentToolCallOutcome struct {
ToolCall *ai.ToolCall
Result AgentToolResult
IsError bool
}
AgentToolCallOutcome is how one tool call ended.
func RunToolCall ¶ added in v0.14.0
func RunToolCall(ctx context.Context, toolCall *ai.ToolCall, options RunToolCallOptions) AgentToolCallOutcome
RunToolCall runs one tool call. Failures (unknown tools, validation errors, blocked calls, tool errors) come back as an error outcome, never an error.
type AgentToolFunc ¶
type AgentToolFunc struct {
AgentToolSpec
Run ToolExecuteFunc
}
AgentToolFunc adapts a function to AgentTool without introducing a second implementation-specific interface.
func (AgentToolFunc) Execute ¶
func (tool AgentToolFunc) Execute( ctx context.Context, toolCallID string, params any, onUpdate AgentToolUpdateCallback, ) (AgentToolResult, error)
func (AgentToolFunc) Spec ¶
func (tool AgentToolFunc) Spec() AgentToolSpec
type AgentToolResult ¶
type AgentToolResult struct {
Content ai.ToolResultContent
Details any
// StructuredContent is the machine-readable result matching the tool's
// output schema, for programmatic callers; the model sees Content.
StructuredContent any
Usage *ai.Usage
AddedToolNames *[]string
// IsError reports a failure without returning an error: the model sees
// Content as an error result, while Details and StructuredContent remain.
IsError bool
Terminate *bool
}
func (AgentToolResult) MarshalJSON ¶
func (result AgentToolResult) MarshalJSON() ([]byte, error)
type AgentToolSpec ¶
type AgentToolSpec struct {
Name string
Label string
Description string
Parameters ai.JSONSchema
ConstrainedSampling *ai.ConstrainedSamplingConfig
PrepareArguments PrepareArgumentsFunc
ExecutionMode ToolExecutionMode
}
type AgentToolUpdateCallback ¶
type AgentToolUpdateCallback func(AgentToolResult)
AgentToolUpdateCallback snapshots accepted updates and returns before event listeners settle. It is scoped to Execute; calls after Execute returns, or racing with its return, may be ignored.
type BeforeToolCallContext ¶
type BeforeToolCallContext struct {
AssistantMessage *ai.AssistantMessage
ToolCall *ai.ToolCall
Args any
Context *AgentContext
}
type BeforeToolCallFunc ¶
type BeforeToolCallFunc func(context.Context, BeforeToolCallContext) (*BeforeToolCallResult, error)
type BeforeToolCallResult ¶
type ConvertToLLMFunc ¶
type ConvertToLLMFunc func(context.Context, AgentMessages) (ai.MessageList, error)
type EventSink ¶
type EventSink func(ctx context.Context, event AgentEvent) error
EventSink handles one event. Parallel tool calls may invoke the same sink concurrently, matching upstream's overlapping event promises, so implementations that mutate shared state must synchronize it. Updates within one tool call arrive one at a time, in the order the tool produced them, and on a goroutine the tool does not wait for: a slow sink lags behind the tool rather than throttling it, up to toolUpdateQueueDepth pending updates.
type FinishTurnFunc ¶ added in v0.14.0
type FinishTurnFunc func(context.Context, TurnContext) (TurnAction, error)
FinishTurnFunc runs after the assistant response and its tool results are final and before turn_end, for error and aborted responses too (their decision is ignored: those remain hard exits). An empty action keeps normal scheduling.
type GetAPIKeyFunc ¶
type GetModelHeadersFunc ¶
type GetQueuedMessagesFunc ¶
type GetQueuedMessagesFunc func(context.Context) (AgentMessages, error)
type GetRequestAuthFunc ¶
type GetRequestAuthFunc func(context.Context, ai.ProviderID) (*RequestAuth, error)
type MessageEndEvent ¶
type MessageEndEvent struct {
Message AgentMessage
}
func (MessageEndEvent) MarshalJSON ¶
func (event MessageEndEvent) MarshalJSON() ([]byte, error)
func (MessageEndEvent) Type ¶
func (MessageEndEvent) Type() AgentEventType
type MessageStartEvent ¶
type MessageStartEvent struct {
Message AgentMessage
}
func (MessageStartEvent) MarshalJSON ¶
func (event MessageStartEvent) MarshalJSON() ([]byte, error)
func (MessageStartEvent) Type ¶
func (MessageStartEvent) Type() AgentEventType
type MessageUpdateEvent ¶
type MessageUpdateEvent struct {
// Upstream constructs this literal with assistantMessageEvent before message.
AssistantMessageEvent ai.AssistantMessageEvent
Message AgentMessage
}
func (MessageUpdateEvent) MarshalJSON ¶
func (event MessageUpdateEvent) MarshalJSON() ([]byte, error)
func (MessageUpdateEvent) Type ¶
func (MessageUpdateEvent) Type() AgentEventType
type ParallelExecutionPreparer ¶
type ParallelExecutionPreparer interface {
PrepareParallelExecution(context.Context, any) (context.Context, func(), error)
}
ParallelExecutionPreparer reserves invocation-ordered resources before a parallel batch is launched. The loop calls it in tool-call source order.
type PrepareArgumentsFunc ¶
type PrepareNextTurnContext ¶
type PrepareNextTurnContext = TurnContext
type PrepareNextTurnFunc ¶
type PrepareNextTurnFunc func(context.Context, PrepareNextTurnContext) (*AgentLoopTurnUpdate, error)
type PrepareRequestContext ¶ added in v0.14.0
type PrepareRequestContext struct {
Context *AgentContext
Model *ai.Model
ThinkingLevel ThinkingLevel
}
PrepareRequestContext is what the next provider request would use.
type PrepareRequestFunc ¶ added in v0.14.0
type PrepareRequestFunc func(context.Context, PrepareRequestContext) (*AgentLoopTurnUpdate, error)
PrepareRequestFunc runs before every provider request, the first included.
type RequestAuth ¶
type RequestAuth struct {
APIKey *string
Headers ai.ProviderHeaders
Env ai.ProviderEnv
BaseURL *string
}
type RunToolCallOptions ¶ added in v0.14.0
type RunToolCallOptions struct {
Tools []AgentTool
AssistantMessage *ai.AssistantMessage
Context AgentContext
Model *ai.Model
BeforeToolCall BeforeToolCallFunc
AfterToolCall AfterToolCallFunc
OnUpdate AgentToolUpdateCallback
}
RunToolCallOptions run one tool call outside the loop, as ExecuteTool does: the call goes through argument preparation, validation and the hooks, against Tools.
type SessionLoop ¶ added in v0.9.0
type SessionLoop func(context.Context, AgentMessages, AgentContext, AgentLoopConfig, EventSink) error
SessionLoop replaces model/tool iteration while retaining Agent state, events, queue ownership and cancellation. A nil loop uses Orb's native implementation. Implementations consume only new prompts; their own session owns prior context.
type ThinkingLevel ¶
type ThinkingLevel = ai.ModelThinkingLevel
const ( ThinkingOff ThinkingLevel = ai.ModelThinkingOff ThinkingMinimal ThinkingLevel = ai.ModelThinkingMinimal ThinkingLow ThinkingLevel = ai.ModelThinkingLow ThinkingMedium ThinkingLevel = ai.ModelThinkingMedium ThinkingHigh ThinkingLevel = ai.ModelThinkingHigh ThinkingXHigh ThinkingLevel = ai.ModelThinkingXHigh ThinkingMax ThinkingLevel = ai.ModelThinkingMax )
type ToolExecuteFunc ¶
type ToolExecuteFunc func( ctx context.Context, toolCallID string, params any, onUpdate AgentToolUpdateCallback, ) (AgentToolResult, error)
type ToolExecutionEndEvent ¶
type ToolExecutionEndEvent struct {
ToolCallID string
ToolName string
Result AgentToolResult
IsError bool
ParentToolCallID string
}
func (ToolExecutionEndEvent) MarshalJSON ¶
func (event ToolExecutionEndEvent) MarshalJSON() ([]byte, error)
func (ToolExecutionEndEvent) Type ¶
func (ToolExecutionEndEvent) Type() AgentEventType
type ToolExecutionMode ¶
type ToolExecutionMode string
const ( ToolExecutionSequential ToolExecutionMode = "sequential" ToolExecutionParallel ToolExecutionMode = "parallel" )
type ToolExecutionStartEvent ¶
type ToolExecutionStartEvent struct {
ToolCallID string
ToolName string
Args map[string]any
ParentToolCallID string
// contains filtered or unexported fields
}
Tool execution events of calls a tool made through ExecuteTool carry ParentToolCallID.
func NewToolExecutionStartEvent ¶
func NewToolExecutionStartEvent(toolCall *ai.ToolCall) ToolExecutionStartEvent
func (ToolExecutionStartEvent) MarshalJSON ¶
func (event ToolExecutionStartEvent) MarshalJSON() ([]byte, error)
func (ToolExecutionStartEvent) Type ¶
func (ToolExecutionStartEvent) Type() AgentEventType
type ToolExecutionUpdateEvent ¶
type ToolExecutionUpdateEvent struct {
ToolCallID string
ToolName string
Args map[string]any
PartialResult AgentToolResult
ParentToolCallID string
// contains filtered or unexported fields
}
func NewToolExecutionUpdateEvent ¶
func NewToolExecutionUpdateEvent(toolCall *ai.ToolCall, partial AgentToolResult) ToolExecutionUpdateEvent
func (ToolExecutionUpdateEvent) MarshalJSON ¶
func (event ToolExecutionUpdateEvent) MarshalJSON() ([]byte, error)
func (ToolExecutionUpdateEvent) Type ¶
func (ToolExecutionUpdateEvent) Type() AgentEventType
type TransformContextFunc ¶
type TransformContextFunc func(context.Context, AgentMessages) (AgentMessages, error)
type TurnAction ¶ added in v0.14.0
type TurnAction string
TurnAction is a FinishTurn decision. TurnEnd ends a normal run after turn_end without touching steering or follow-up queues; TurnContinue ensures one more provider request, which queued work may satisfy.
const ( TurnEnd TurnAction = "end" TurnContinue TurnAction = "continue" )
type TurnContext ¶ added in v0.14.0
type TurnContext struct {
Message *ai.AssistantMessage
ToolResults []*ai.ToolResultMessage
Context *AgentContext
NewMessages AgentMessages
}
TurnContext describes a completed turn: the assistant response, its tool results, the context after them and everything the run appended so far.
type TurnEndEvent ¶
type TurnEndEvent struct {
Message AgentMessage
ToolResults []*ai.ToolResultMessage
}
func (TurnEndEvent) MarshalJSON ¶
func (event TurnEndEvent) MarshalJSON() ([]byte, error)
func (TurnEndEvent) Type ¶
func (TurnEndEvent) Type() AgentEventType
type TurnStartEvent ¶
type TurnStartEvent struct{}
func (TurnStartEvent) MarshalJSON ¶
func (TurnStartEvent) MarshalJSON() ([]byte, error)
func (TurnStartEvent) Type ¶
func (TurnStartEvent) Type() AgentEventType