Documentation
¶
Index ¶
- Variables
- func On[T HookEvent](r *HookRegistry, hook HookFunc[T])
- func Stream(ctx context.Context, agent Agent, messages []Message, opts AgentOptions) iter.Seq2[StreamEvent, error]
- type AfterModelInvokeHook
- type AfterStreamHook
- type AfterToolCallHook
- type AfterToolCycleHook
- type Agent
- type AgentOptions
- type BeforeModelInvokeHook
- type BeforeStreamHook
- type BeforeToolCallHook
- type BeforeToolCycleHook
- type Block
- type BlockType
- type FuncTool
- type FuncToolOptions
- type Hook
- type HookEvent
- type HookFunc
- type HookRegistry
- type InvokeResponse
- type JSONMarshaler
- type LoggingPlugin
- type Media
- type MediaBlock
- type MediaDelta
- type MediaType
- type Message
- type OnMessageAppendedHook
- type OnStreamEventHook
- type Plugin
- type Role
- type StopReason
- type StreamEvent
- type StreamEventType
- type TextBlock
- type Tool
- type ToolResultBlock
- type ToolUseBlock
Constants ¶
This section is empty.
Variables ¶
var ErrAbort = errors.New("bond: operation aborted by hook")
ErrAbort is returned by a hook to signal that the current operation should be cancelled. Use with Before* hooks to prevent execution.
Functions ¶
func On ¶
func On[T HookEvent](r *HookRegistry, hook HookFunc[T])
On registers a hook for the event type T. The type is inferred from the generic parameter — no event instance needed. Hooks fire in registration order (FIFO) when Notify is called for the corresponding event type.
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 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 BeforeModelInvokeHook ¶
type BeforeModelInvokeHook struct {
Messages []Message // conversation state being sent to the model
}
BeforeModelInvokeHook fires before calling the provider's Stream method.
type BeforeStreamHook ¶
type BeforeStreamHook struct {
Messages []Message
}
BeforeStreamHook fires before the agent loop begins.
type BeforeToolCallHook ¶
type BeforeToolCallHook struct {
ToolUse *ToolUseBlock
}
BeforeToolCallHook fires before a single tool is executed. Return ErrAbort to skip this tool call.
type BeforeToolCycleHook ¶
type BeforeToolCycleHook struct {
ToolCalls []*ToolUseBlock
}
BeforeToolCycleHook fires before the batch of tool calls begins.
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.
type HookFunc ¶
HookFunc adapts a typed function into a Hook. The function receives the concrete event type directly.
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. All hooks are called; errors are joined. If any hook returns ErrAbort, the joined error will contain it (check with errors.Is).
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 OnMessageAppendedHook ¶
type OnMessageAppendedHook struct {
Message Message
}
OnMessageAppendedHook fires when a message is appended to conversation history.
type OnStreamEventHook ¶
type OnStreamEventHook struct {
Event StreamEvent
}
OnStreamEventHook fires for each raw StreamEvent received from the provider.
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.
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 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. |
|
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. |
|
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. |
|
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. |
|
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. |