Documentation
¶
Index ¶
- Variables
- func OnAfter[T AfterHookEvent](r *HookRegistry, hook AfterHookFunc[T])
- func OnBefore[T BeforeHookEvent](r *HookRegistry, hook BeforeHookFunc[T])
- func Stream(ctx context.Context, agent Agent, messages []Message, opts AgentOptions) iter.Seq2[StreamEvent, error]
- type AfterHookEvent
- type AfterHookFunc
- type AfterMessageAppendedHook
- type AfterModelInvokeHook
- type AfterStreamHook
- type AfterToolCallHook
- type AfterToolCycleHook
- type Agent
- type AgentOptions
- type BeforeHookEvent
- type BeforeHookFunc
- type BeforeModelInvokeHook
- type BeforeStreamEventHook
- type BeforeStreamHook
- type BeforeToolCallHook
- type BeforeToolCycleHook
- type Block
- type BlockType
- type FuncTool
- type FuncToolOptions
- type Hook
- type HookEvent
- type HookRegistry
- type InvokeResponse
- type JSONMarshaler
- type LoggingPlugin
- type Media
- type MediaBlock
- type MediaDelta
- type MediaType
- type Message
- type Plugin
- type Role
- type StopReason
- type StreamEvent
- type StreamEventType
- type TextBlock
- type Tool
- type ToolConfirmationFunc
- type ToolConfirmationProvider
- type ToolResultBlock
- type ToolUseBlock
Constants ¶
This section is empty.
Variables ¶
var ErrAbort = errors.New("bond: operation aborted by hook")
ErrAbort is returned by a before-hook to signal that the current operation should be cancelled. Use with Before* hooks to prevent execution.
Functions ¶
func OnAfter ¶ added in v0.2.0
func OnAfter[T AfterHookEvent](r *HookRegistry, hook AfterHookFunc[T])
OnAfter registers an observer hook for the after-event type T. Observer hooks fire in registration order (FIFO). They cannot return errors and cannot interrupt the agent loop.
func OnBefore ¶ added in v0.2.0
func OnBefore[T BeforeHookEvent](r *HookRegistry, hook BeforeHookFunc[T])
OnBefore registers a gate hook for the before-event type T. Gate hooks fire in registration order (FIFO). Return ErrAbort or any error to prevent the guarded operation.
func Stream ¶
func Stream(ctx context.Context, agent Agent, messages []Message, opts AgentOptions) iter.Seq2[StreamEvent, error]
Stream runs the full agent loop: it streams from the provider, and when the model requests tool use, it executes the tools, appends results to the conversation, and re-invokes the provider. Events are yielded to the caller transparently across turns.
Types ¶
type AfterHookEvent ¶ added in v0.2.0
type AfterHookEvent interface {
HookEvent
// contains filtered or unexported methods
}
AfterHookEvent is implemented by observer hooks that fire after an operation. Observer hooks are informational — their handlers cannot return errors and cannot interrupt the agent loop.
type AfterHookFunc ¶ added in v0.2.0
type AfterHookFunc[T AfterHookEvent] func(context.Context, T)
AfterHookFunc is a handler for after (observer) events. It receives the concrete event type and cannot return an error — observer hooks are fire-and-forget.
func (AfterHookFunc[T]) NotifyHookEvent ¶ added in v0.2.0
func (fn AfterHookFunc[T]) NotifyHookEvent(ctx context.Context, event HookEvent) error
NotifyHookEvent implements Hook. Always returns nil since after-hooks cannot produce errors.
type AfterMessageAppendedHook ¶ added in v0.2.0
type AfterMessageAppendedHook struct {
Message Message
}
AfterMessageAppendedHook fires when a message is appended to conversation history.
type AfterModelInvokeHook ¶
type AfterModelInvokeHook struct {
Blocks []Block // assembled assistant content blocks
StopReason StopReason // why the model stopped
}
AfterModelInvokeHook fires after a provider Stream call has fully drained.
type AfterStreamHook ¶
type AfterStreamHook struct {
Messages []Message // full conversation history at completion
}
AfterStreamHook fires when the agent loop completes.
type AfterToolCallHook ¶
type AfterToolCallHook struct {
ToolUse *ToolUseBlock
Result *ToolResultBlock
}
AfterToolCallHook fires after a single tool execution completes.
type AfterToolCycleHook ¶
type AfterToolCycleHook struct {
Results []*ToolResultBlock
}
AfterToolCycleHook fires after all tool calls in a cycle complete.
type Agent ¶
type Agent interface {
// Stream sends the conversation messages to the model and returns
// an iterator of streaming events. The last message in the slice
// is treated as the current prompt; preceding messages are context.
Stream(ctx context.Context, messages []Message) iter.Seq2[StreamEvent, error]
}
Agent is the core interface for streaming LLM interactions.
type AgentOptions ¶
type AgentOptions struct {
Tools []Tool
Plugins []Plugin
MaxTurns int // max tool-use round-trips; 0 means unlimited
}
AgentOptions configures the agent loop.
type BeforeHookEvent ¶ added in v0.2.0
type BeforeHookEvent interface {
HookEvent
// contains filtered or unexported methods
}
BeforeHookEvent is implemented by gate hooks that fire before an operation. Gate hooks can return errors to prevent execution. Return ErrAbort to gracefully skip the operation, or any other error to halt with that error.
type BeforeHookFunc ¶ added in v0.2.0
type BeforeHookFunc[T BeforeHookEvent] func(context.Context, T) error
BeforeHookFunc is a handler for before (gate) events. It receives the concrete event type and may return an error to prevent the operation.
func (BeforeHookFunc[T]) NotifyHookEvent ¶ added in v0.2.0
func (fn BeforeHookFunc[T]) NotifyHookEvent(ctx context.Context, event HookEvent) error
NotifyHookEvent implements Hook.
type BeforeModelInvokeHook ¶
type BeforeModelInvokeHook struct {
Messages []Message // conversation state being sent to the model
}
BeforeModelInvokeHook fires before calling the provider's Stream method. Return ErrAbort to skip the invocation, or any error to stop the loop.
type BeforeStreamEventHook ¶ added in v0.2.0
type BeforeStreamEventHook struct {
Event StreamEvent
}
BeforeStreamEventHook fires before each raw StreamEvent is processed. Return ErrAbort to stop consuming the stream.
type BeforeStreamHook ¶
type BeforeStreamHook struct {
Messages []Message
}
BeforeStreamHook fires before the agent loop begins. Return ErrAbort to cancel the stream, or any error to stop with that error.
type BeforeToolCallHook ¶
type BeforeToolCallHook struct {
ToolUse *ToolUseBlock
}
BeforeToolCallHook fires before a single tool is executed. Return ErrAbort or any error to skip this tool call and surface the error as a tool result to the model.
type BeforeToolCycleHook ¶
type BeforeToolCycleHook struct {
ToolCalls []*ToolUseBlock
}
BeforeToolCycleHook fires before the batch of tool calls begins. Return ErrAbort to skip the entire tool cycle, or any error to abort all tool calls with error results.
type Block ¶
type Block interface {
// contains filtered or unexported methods
}
Block is the interface satisfied by all content blocks.
type FuncTool ¶
type FuncTool struct {
// contains filtered or unexported fields
}
FuncTool is a Tool implementation backed by a function. The zero value is not usable; create instances with NewFuncTool.
func (FuncTool) Description ¶
func (FuncTool) InputSchema ¶
func (FuncTool) OutputSchema ¶
type FuncToolOptions ¶
type HookEvent ¶
type HookEvent interface {
// contains filtered or unexported methods
}
HookEvent is the sealed interface for all hook event types. Every hook event is either a BeforeHookEvent (gate) or AfterHookEvent (observer).
type HookRegistry ¶
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry manages hooks keyed by event type.
func (*HookRegistry) Notify ¶
func (r *HookRegistry) Notify(ctx context.Context, event HookEvent) error
Notify dispatches an event to all registered hooks for that event type. For before-events, all hooks are called and errors are joined. If any hook returns ErrAbort, the joined error will contain it. For after-events, hooks are called but errors are always nil (since AfterHookFunc cannot produce errors).
type InvokeResponse ¶
type InvokeResponse struct {
// Text is the concatenated text output from the agent.
Text string
// Media contains any media content produced by the agent.
Media []Media
// StopReason indicates why the agent stopped.
StopReason StopReason
}
InvokeResponse holds the collected result of a synchronous agent invocation.
func Invoke ¶
func Invoke(ctx context.Context, agent Agent, messages []Message, opts AgentOptions) (*InvokeResponse, error)
Invoke runs the full agent loop synchronously, collecting all streamed events into a single InvokeResponse. This is a convenience wrapper over Stream for cases where streaming is not needed.
type JSONMarshaler ¶
type LoggingPlugin ¶
func (*LoggingPlugin) Init ¶
func (p *LoggingPlugin) Init(registry *HookRegistry)
func (*LoggingPlugin) Name ¶
func (p *LoggingPlugin) Name() string
func (*LoggingPlugin) Tools ¶
func (p *LoggingPlugin) Tools() []Tool
type Media ¶
type Media struct {
// MIMEType is the media type (e.g. "image/png", "audio/wav").
MIMEType string
// Data is the raw bytes.
Data []byte
}
Media represents a complete piece of media content in a response.
type MediaBlock ¶
type MediaBlock struct {
Type MediaType
MIMEType string
Source io.Reader // content payload; wrap bytes with bytes.NewReader
SourceURI string // optional URI reference (e.g. S3 key, URL)
}
MediaBlock holds binary content (images, audio, video, documents).
type MediaDelta ¶
type MediaDelta struct {
// MIMEType is the media type (e.g. "image/png", "audio/wav").
MIMEType string
// Data is the raw bytes for this chunk.
Data []byte
}
MediaDelta represents a chunk of binary/media content in a stream.
type MediaType ¶
type MediaType string
MediaType describes the kind of binary content in a MediaBlock.
type Message ¶
type Message struct {
Role Role
Content []Block
// Metadata holds provider-specific annotations (reasoning traces,
// citations, guard content, cache points, etc.) that don't map
// universally across providers.
Metadata map[string]any
}
Message represents a single turn in a conversation.
func Conversation ¶
Conversation builds a message list from alternating user/assistant strings. The first string is user, second is assistant, third is user, etc. Useful for constructing few-shot examples or test fixtures.
func ImagePrompt ¶
ImagePrompt creates a user message with text and an image from a URI.
func MultiBlockPrompt ¶
MultiBlockPrompt creates a user message from arbitrary blocks.
func TextPrompt ¶
TextPrompt is a convenience helper that wraps a plain string into the []Message format expected by Agent.Stream.
type Plugin ¶
type Plugin interface {
// Name identifies the plugin (used for logging/debugging).
Name() string
// Tools returns the tools this plugin contributes to the agent loop.
Tools() []Tool
// Init registers hooks on the provided registry. Called once during
// stream setup before the loop begins.
Init(registry *HookRegistry)
}
Plugin bundles tools and hook registrations into a reusable unit.
func NewHooksPlugin ¶
func NewHooksPlugin(name string, onInit func(*HookRegistry)) Plugin
NewHooksPlugin creates a Plugin that registers hooks via the provided callback but does not contribute any tools. This is useful for cross-cutting concerns like logging, metrics, or guardrails that only need to observe or modify the agent loop through hooks.
func NewToolConfirmationPlugin ¶ added in v0.2.0
func NewToolConfirmationPlugin(provider ToolConfirmationProvider) Plugin
NewToolConfirmationPlugin returns a Plugin that intercepts BeforeToolCallHook and invokes the given provider before each tool execution. If the provider denies the call, the hook returns ErrAbort which causes the agent loop to skip the tool and return an error result to the model.
The provider is responsible for deciding which tools require confirmation. For example, it may allow all read-only tools unconditionally and only prompt for write operations.
type StopReason ¶
type StopReason string
StopReason indicates why the model stopped generating.
const ( StopReasonEnd StopReason = "end" // natural end of response StopReasonToolUse StopReason = "tool_use" // paused to call a tool StopReasonLength StopReason = "length" // hit max token limit )
type StreamEvent ¶
type StreamEvent struct {
Type StreamEventType
// TextDelta is populated when Type == StreamEventTextDelta.
TextDelta string
// MediaDelta is populated when Type == StreamEventMediaDelta.
MediaDelta *MediaDelta
// ToolUse is populated when Type == StreamEventToolUse.
ToolUse *ToolUseBlock
// StopReason is populated when Type == StreamEventStop.
StopReason StopReason
// Metadata carries provider-specific event data (usage stats, trace IDs, etc.)
Metadata map[string]any
}
StreamEvent represents a single event in a streaming response.
type StreamEventType ¶
type StreamEventType string
StreamEventType identifies what kind of event was emitted during streaming.
const ( // StreamEventStart signals the beginning of the response stream. StreamEventStart StreamEventType = "start" // StreamEventTextDelta delivers an incremental chunk of text. StreamEventTextDelta StreamEventType = "text_delta" // StreamEventMediaDelta delivers a chunk of binary/media content. StreamEventMediaDelta StreamEventType = "media_delta" // StreamEventToolUse signals the model wants to invoke a tool. StreamEventToolUse StreamEventType = "tool_use" // StreamEventStop signals the response is complete. StreamEventStop StreamEventType = "stop" )
type Tool ¶
type Tool interface {
// Name is the tool identifier the model will reference.
Name() string
// Description helps the model decide when to use this tool.
Description() string
// InputSchema is the JSON schema describing expected input parameters.
InputSchema() json.Marshaler
// Run executes the tool and returns result blocks.
Run(ctx context.Context, input json.RawMessage) ([]Block, error)
}
Tool represents a tool the agent can invoke during streaming.
func NewFuncTool ¶
func NewFuncTool[In, Out any](fn func(context.Context, In) (Out, error), options FuncToolOptions) (Tool, error)
NewFuncTool creates a Tool backed by a typed function. The function's input is unmarshaled from JSON, and its output is marshaled back into a TextBlock. Returns an error if required options (Name, Description) or the handler are missing.
func ToolsFromContext ¶
ToolsFromContext retrieves the tools available for the current invocation. Providers use this to include tool definitions in API requests. Returns nil if no tools are configured.
type ToolConfirmationFunc ¶ added in v0.2.0
type ToolConfirmationFunc func(ctx context.Context, toolUse *ToolUseBlock) (bool, error)
ToolConfirmationFunc adapts a plain function into a ToolConfirmationProvider.
func (ToolConfirmationFunc) ConfirmToolUse ¶ added in v0.2.0
func (f ToolConfirmationFunc) ConfirmToolUse(ctx context.Context, toolUse *ToolUseBlock) (bool, error)
ConfirmToolUse implements ToolConfirmationProvider.
type ToolConfirmationProvider ¶ added in v0.2.0
type ToolConfirmationProvider interface {
// ConfirmToolUse is called before each tool invocation. Return true to
// allow the call, or false to deny it. A denied call aborts with
// [ErrAbort] and surfaces an error result to the model.
ConfirmToolUse(ctx context.Context, toolUse *ToolUseBlock) (bool, error)
}
ToolConfirmationProvider decides whether a tool call should proceed. Implementations may prompt a user, check a policy, or consult an external service. The provider receives the full ToolUseBlock (tool name and input) and returns whether to allow or deny execution.
type ToolResultBlock ¶
type ToolResultBlock struct {
ToolUseID string
Content []Block // typically TextBlock or MediaBlock
IsError bool
}
ToolResultBlock holds the response from a tool invocation.
type ToolUseBlock ¶
type ToolUseBlock struct {
ID string
Name string
Input json.RawMessage
}
ToolUseBlock represents the model requesting a tool invocation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agent provides utilities for using bond agents as tools, enabling sub-agent orchestration patterns.
|
Package agent provides utilities for using bond agents as tools, enabling sub-agent orchestration patterns. |
|
agentacp
Package agentacp provides ACP (Agent Client Protocol) building blocks and a proxy client for connecting to external ACP-compatible agents.
|
Package agentacp provides ACP (Agent Client Protocol) building blocks and a proxy client for connecting to external ACP-compatible agents. |
|
Package bondtest provides test utilities for the bond agent framework.
|
Package bondtest provides test utilities for the bond agent framework. |
|
extra
|
|
|
delegation
Package delegation enables transparent tool delegation between agents communicating over the A2A protocol.
|
Package delegation enables transparent tool delegation between agents communicating over the A2A protocol. |
|
toolbox
Package toolbox provides a suite of reusable tools for Bond agents that cover common system interactions: shell command execution, HTTP fetching, file I/O, and environment variable access.
|
Package toolbox provides a suite of reusable tools for Bond agents that cover common system interactions: shell command execution, HTTP fetching, file I/O, and environment variable access. |
|
toolregistry
Package toolregistry provides a plugin that exposes a large collection of tools through a stable 3-tool gateway: list_tools, describe_tool, use_tool.
|
Package toolregistry provides a plugin that exposes a large collection of tools through a stable 3-tool gateway: list_tools, describe_tool, use_tool. |
|
internal
|
|
|
provider
|
|
|
bedrock
Package bedrock provides a bond.Agent implementation backed by the Amazon Bedrock Converse streaming API.
|
Package bedrock provides a bond.Agent implementation backed by the Amazon Bedrock Converse streaming API. |
|
internal/openai
Requirement: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 — map Bond messages to OpenAI format Requirement: 3.1, 3.2, 3.3 — map Bond tools to OpenAI tool definitions
|
Requirement: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 — map Bond messages to OpenAI format Requirement: 3.1, 3.2, 3.3 — map Bond tools to OpenAI tool definitions |
|
ollama
Package ollama provides a bond.Agent implementation backed by OpenAI-compatible Chat Completions endpoints (Ollama, LiteLLM, vLLM).
|
Package ollama provides a bond.Agent implementation backed by OpenAI-compatible Chat Completions endpoints (Ollama, LiteLLM, vLLM). |
|
openai
Package openai provides a bond.Agent implementation backed by the OpenAI Chat Completions API (https://api.openai.com).
|
Package openai provides a bond.Agent implementation backed by the OpenAI Chat Completions API (https://api.openai.com). |
|
Package runtime provides protocol handlers for serving bond agents over A2A, HTTP, and MCP.
|
Package runtime provides protocol handlers for serving bond agents over A2A, HTTP, and MCP. |
|
acp
Package acp provides an ACP (Agent Client Protocol) handler that serves bond agents over JSON-RPC 2.0 via stdio or other transports.
|
Package acp provides an ACP (Agent Client Protocol) handler that serves bond agents over JSON-RPC 2.0 via stdio or other transports. |
|
agentcore
Package agentcore provides convenience constructors for running bond agents on AWS Bedrock AgentCore Runtime.
|
Package agentcore provides convenience constructors for running bond agents on AWS Bedrock AgentCore Runtime. |
|
Package toolmcp adapts MCP server tools for use in bond agent loops.
|
Package toolmcp adapts MCP server tools for use in bond agent loops. |