Documentation
¶
Overview ¶
Package afk (Agent Framework Kit / Away From Keyboard) provides a small, reusable ReAct agent loop built directly on the official Anthropic SDK (github.com/anthropics/anthropic-sdk-go).
It is anthropic-first by design: messages are the SDK's native anthropic.BetaMessageParam, there is no provider-compat layer, and tool calls are dispatched through a simple Tool interface. The loop streams assistant text to a StreamSink as it is produced, executes tool_use blocks, feeds the results back, and repeats until the model stops requesting tools or the iteration budget is exhausted.
This package deliberately lives in the root module (not agentboot) because it relies on Anthropic SDK v1.45 APIs that are wired in via the root go.mod replace directive; agentboot pins an older SDK without that replace.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// BaseURL and APIKey point the SDK at the tingly-box gateway.
BaseURL string
APIKey string
// Model is the model identifier (for tingly-box this is a bot-UUID rule).
Model string
// System is the system prompt.
System string
// MaxTokens caps a single response; defaults to 4096 when zero.
MaxTokens int64
// Temperature is optional; nil leaves it unset.
Temperature *float64
// MaxIterations caps tool-use rounds; defaults to 20 when zero.
MaxIterations int
// StreamText controls how assistant text reaches the StreamSink.
//
// Default (false): aggregated — the engine buffers each assistant turn's
// text and calls StreamSink.OnText once, with the complete turn text. This
// is the safe default while consumers don't yet handle incremental output.
//
// true: streaming — OnText is called per text fragment as it arrives. The
// engine always consumes the model's HTTP stream either way; this flag only
// changes the granularity of the OnText fan-out to the sink.
StreamText bool
// Tools are the callable tools exposed to the model.
Tools []Tool
}
Config configures an Engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs the ReAct loop against a configured model and toolset.
func (*Engine) Run ¶
func (e *Engine) Run( ctx context.Context, history []anthropic.BetaMessageParam, userText string, sink StreamSink, ) ([]anthropic.BetaMessageParam, string, error)
Run executes the ReAct loop. It appends the user prompt to history, then streams/executes until the model produces a final answer (no tool_use) or the iteration budget is reached.
history is the prior conversation as native SDK beta message params (may be empty). It returns the full updated message slice (history + this exchange) so the caller can persist it, plus the final assistant text.
type StreamSink ¶
type StreamSink interface {
// OnText is called with assistant text. By default (aggregated mode) it is
// called once per assistant turn with the full text; in streaming mode it
// is called many times per turn with partial fragments.
OnText(delta string)
// OnToolCall is called when the model invokes a tool, before execution.
OnToolCall(name string, input json.RawMessage)
// OnToolResult is called after a tool finishes, with the textual result and
// whether it was an error.
OnToolResult(name string, result string, isErr bool)
}
StreamSink receives incremental updates as the loop runs. All methods are optional in spirit — a nil StreamSink disables streaming entirely, and the engine never assumes any method has side effects it depends on.
Whether OnText is called per-fragment or once per turn with the aggregated text is controlled by Config.StreamText (default: aggregated). See that field.
type Tool ¶
type Tool interface {
// Param returns the full BetaToolParam sent to the model. Name is also used
// as the dispatch key when routing tool_use blocks back to this tool.
Param() anthropic.BetaToolParam
// Call executes the tool with the raw JSON arguments produced by the model
// and returns the textual result. A non-nil error is reported back to the
// model as an error tool_result (the loop itself does not abort).
Call(ctx context.Context, rawInput json.RawMessage) (string, error)
}
Tool is a single callable tool exposed to the model.
Param describes the tool to the model (name, description, input schema) as a native BetaToolParam — no conversion layer. Call executes it; the raw JSON input from the model is passed through unmodified so each tool owns its own argument decoding.