agentdemo

command
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

agentdemo: the agent loop, with no key and no network

agentdemo runs AgentKit's real agent loop end to end against provider/faux, a scripted provider that replays canned model turns. Only the model is fake: the loop, the tool executor and the Anthropic request encoder are the shipped code. It shows, in four short sections, behaviour that a naive agent loop gets wrong. Start here if you want to see the machinery without spending anything.

Run it

go run ./examples/agentdemo

There are no flags. The output uses ANSI colours. The first section looks like this:

── 1. The loop, streamed ─────────────────────────────────────────
Let me count those.  → calling word_count (call_1)
  ← {"data":{"count":9},"ok":true}
  [turn 0 ended: tool_use]
That sentence has 9 words.
  [turn 1 ended: stop]

final: "That sentence has 9 words."
turns: 2, stop: end_turn

What it shows

  1. The loop, streamed. A two-turn run consumed as an event stream (TextDeltaEvent, ToolCallStartEvent, ToolResultEvent, TurnEndEvent), then stream.RunResult().
  2. Tool calls drive the loop, not stop_reason. Some providers report stop alongside tool calls; the loop runs the tools whatever the stop reason says.
  3. A truncated tool call is never executed. When a turn hits the output token limit, its tool calls get an error result asking the model to re-issue them, and the loop continues.
  4. Transcript repair. An aborted turn and its orphaned tool result are dropped from the request sent to the provider; the stored history is left complete.

The code that matters

A tool is a core.Tool with a schema built from combinators and a handler. The loop wraps the handler's return in {"ok":true,"data":…}:

core.Tool{
	Name:        "word_count",
	Description: "Count the words in a piece of text",
	InputSchema: schema.Object(
		schema.Prop("text", schema.String("The text to count words in")),
		schema.Opt("unique", schema.Bool("Count distinct words only")),
	),
	Handler: func(ctx context.Context, in json.RawMessage) (json.RawMessage, error) { … },
}

A scripted model and the minimum agent. The faux provider is a core.ProviderClient, so it goes in Client; with a real model you leave Client out and set Provider and Model (see codingagent):

p := faux.New(
	faux.Turn{Blocks: []core.ContentBlock{
		faux.FauxText("Let me count those."),
		faux.FauxToolCall("call_1", "word_count", `{"text":"the quick brown fox"}`),
	}, StopReason: core.StopReasonToolUse},
	faux.Turn{Blocks: []core.ContentBlock{faux.FauxText("4 words.")}, StopReason: core.StopReasonStop},
)
agent, err := agentkit.New(agentkit.Config{
	Client:     p,
	Model:      faux.Model().ID,
	System:     "You are a helpful assistant.",
	Toolset:    agentkit.Toolset{Tools: []core.Tool{wordCount()}},
	MaxTurns:   8,
	MaxCostUSD: 0.50,
})

p.ChunkSize splits text into deltas so streaming is visible, and p.Requests() returns what the loop sent.

agentdemo is a tour, not a template: for a minimal real program start with codingagent or customtools.

Further reading

Documentation

Overview

Command agentdemo runs AgentKit end to end with no API key and no network.

go run ./examples/agentdemo

It drives the real loop against the scripted faux provider, so every behaviour it prints is the shipped implementation, not a mock of it. Read the output alongside the source: each section demonstrates one requirement that the PRD got wrong before it was corrected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL