local-agent

command
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 11 Imported by: 0

README

Local Agent Example

This example is a small Gemini-backed CLI agent built directly on the Glue library. It registers a local_time tool, streams the assistant text to stdout, and persists sessions through stores/file.

The implementation lives in main.go and is intentionally short: it shows the full shape of a Glue application — provider, store, a typed tool defined with glue.NewTool[T], session management, and WithStreamWriter output — in around 100 lines. For a guided, step-by-step walkthrough of these same pieces, see docs/building-agents.md.

Run

Set a Gemini API key, then run:

export GEMINI_API_KEY=...
go run ./examples/local-agent \
  --prompt "Use local_time for America/Toronto and summarize it." \
  --id demo

Flags:

  • --prompt (required) — prompt text
  • --id — session id (default example)
  • --model — Gemini model id (default gemini-2.5-flash)
  • --store — session store directory (default .glue/example-sessions)

The session is persisted to disk, so re-running with the same --id continues the conversation.

Test

go test ./examples/local-agent

Three offline tests cover the local_time tool's happy path, missing timezone arg, and invalid JSON arg. Because the tool is built with glue.NewTool[T], both failure cases surface as an error ToolResult (IsError) the model can recover from rather than a Go error that crashes the loop. The live test (TestLiveLocalAgent) is gated behind GEMINI_API_KEY and skipped in CI.

Compare to cmd/glue

cmd/glue/run is the generic local CLI; this example is a self-contained program showing how to build a tool-calling agent in your own main.go. The two share glue.NewAgent + gemini.New + stores/file + the same event-streaming pattern.

Documentation

Overview

Command local-agent is a small Gemini-backed CLI built directly on the glue library. It registers a local_time tool so the model can call into the Go process to get the current wall-clock time for a requested timezone label, streams the assistant text to stdout, and persists sessions through stores/file. Use it as a smoke test and as a tutorial for new applications.

Jump to

Keyboard shortcuts

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