rein

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT

README

rein

CI Go Reference

English | 简体中文

rein is a Go framework for building LLM agents: the agent loop, tools, sessions and the runtime around them, with Anthropic models as the first-class target.

Status: v0.x. The API may change in incompatible ways before v1. Requires Go 1.25+.

Features

  • Model providers: Anthropic first, plus OpenAI, Gemini and DeepSeek behind one interface: messages, streaming events, classified errors, structured output and media input.
  • Agent loop: parallel tool execution with timeouts and result truncation, steering and follow-up messages during a run, and a middleware chain wrapping runs, turns, model calls and tool calls.
  • Tools: typed tools from a parameter struct, with the schema generated for you; toolsets that provide tools per session.
  • Sub-agents and background tasks: delegate work to sub-agents running in the background; run shell commands in the background too.
  • Runner: sessions persisted through a store interface, message queues, automatic context compaction and an event stream.
  • Built-in tools: skills, a checklist, shell, background task management, and MCP servers.

Install

go get github.com/coldcoder126/rein

Quick start

type weatherArgs struct {
	City string `json:"city" jsonschema:"description=City name"`
}

weather := tool.New("get_weather", "Get the current weather of a city.",
	func(ctx *tool.Context, in weatherArgs) (*tool.Result, error) {
		return tool.Text(in.City + ": sunny, 22°C"), nil
	})

a := &agent.Agent{
	Instruction: "You are a helpful assistant.",
	Model:       anthropic.New(anthropic.Config{APIKey: os.Getenv("ANTHROPIC_API_KEY")}),
	Tools:       []tool.Tool{weather},
}
result, err := a.Run(ctx, agent.Text("What's the weather in Paris?"))
if err != nil {
	log.Fatal(err)
}
fmt.Println(result.Final.TextContent())

The full program is in examples/quickstart.

Core concepts

Package Responsibility
chat Model protocol: messages, stream events, errors, structured output, model middleware; providers live in chat/provider/*
tool Tool interface, execution context, results, typed tools, toolsets
agent The Agent definition and its loop; sub-agents as a tool
session Sessions and messages, the store interface, an in-memory store
runner Runtime: loads history per session, drives the Agent, persistence, queues, compaction, background tasks, events

Define tools → put them in an agent.Agent → hand the Agent and a store to a runner.Runner → call Run or Stream with a session ID. Without sessions, call Agent.Run directly. See docs/architecture.md for the design.

Packages

Package Description
chat/provider/anthropic Anthropic Messages API and compatible endpoints
chat/provider/openai OpenAI Responses API and compatible endpoints
chat/provider/gemini Google Gemini
chat/provider/deepseek DeepSeek
chat/imageproc Normalizing images (format, size) before they enter history
tool/skill Skills: instructions and resources loaded on demand
tool/todo A checklist the model keeps for multi-step tasks
tool/shell Shell commands, in the foreground or background, through a pluggable executor
tool/task Listing and stopping background tasks
tool/mcp Tools of MCP servers, over stdio or Streamable HTTP
x/... Experimental packages, not covered by any stability promise

Examples

Example Shows
quickstart An Agent with one typed tool
runner Sessions that remember earlier turns, with streamed replies
subagent Sub-agents working in the background, results combined by the main Agent
mcp Using the tools of an MCP server over stdio
approval A middleware asking a human before shell commands run

Run them with ANTHROPIC_API_KEY=... go run ./examples/<name>.

Out of scope

rein runs agents; the product around them is yours. It does not include:

  • fan-out of events to many connections, or resuming a stream after a client reconnects;
  • permission and approval policies (middleware gives you the hooks);
  • sandboxes for executing commands (implement shell.Executor);
  • production session stores (implement session.Store; only an in-memory store ships);
  • MCP resources, prompts, sampling and elicitation.

Acknowledgements

The design of rein draws on pi, the agent harness by Earendil Works.

License

MIT

Directories

Path Synopsis
Package agent defines the Agent: a set of instructions, a model and tools, plus the decision loop that drives them.
Package agent defines the Agent: a set of instructions, a model and tools, plus the decision loop that drives them.
Package chat defines the lowest-level LLM chat abstraction.
Package chat defines the lowest-level LLM chat abstraction.
chattest
Package chattest provides a scripted Client for testing users of chat.Client, plus a stream contract checker.
Package chattest provides a scripted Client for testing users of chat.Client, plus a stream contract checker.
imageproc
Package imageproc normalizes an image once before it enters the conversation history: it detects the format, converts it to a format models accept, and limits its dimensions and size.
Package imageproc normalizes an image once before it enters the conversation history: it detects the format, converts it to a format models accept, and limits its dimensions and size.
provider/anthropic
Package anthropic implements chat.Client with the Anthropic Messages API.
Package anthropic implements chat.Client with the Anthropic Messages API.
provider/deepseek
Package deepseek provides constructors for DeepSeek chat.Clients.
Package deepseek provides constructors for DeepSeek chat.Clients.
provider/gemini
Package gemini implements chat.Client for Gemini on top of the official google.golang.org/genai SDK.
Package gemini implements chat.Client for Gemini on top of the official google.golang.org/genai SDK.
provider/openai
Package openai implements chat.Client with the OpenAI Responses API; it also works with endpoints compatible with the Responses API (such as DeepSeek).
Package openai implements chat.Client with the OpenAI Responses API; it also works with endpoints compatible with the Responses API (such as DeepSeek).
api/anthropic module
api/gemini module
api/openai module
examples
approval command
Approval: a WrapTool middleware asks a human before every shell command runs.
Approval: a WrapTool middleware asks a human before every shell command runs.
mcp command
MCP: an Agent uses the tools of an MCP server over stdio.
MCP: an Agent uses the tools of an MCP server over stdio.
quickstart command
Quickstart: an Agent with one typed tool, run directly without sessions.
Quickstart: an Agent with one typed tool, run directly without sessions.
runner command
Runner: sessions that remember earlier turns, with the reply streamed as it is generated.
Runner: sessions that remember earlier turns, with the reply streamed as it is generated.
subagent command
Sub-agents: the main Agent delegates work to sub-agents running in the background and combines their results.
Sub-agents: the main Agent delegates work to sub-agents running in the background and combines their results.
Package runner is the Agent runtime: it loads history by session ID, builds the context of each run, drives the Agent, persists messages, manages queued messages and history compaction, and hands the events of a run to its caller.
Package runner is the Agent runtime: it loads history by session ID, builds the context of each run, drives the Agent, persists messages, manages queued messages and history compaction, and hands the events of a run to its caller.
Package session defines the persistence model of sessions: sessions, session messages and the store interface.
Package session defines the persistence model of sessions: sessions, session messages and the store interface.
Package tool defines the tools an Agent can call: the tool interface, the execution context, results, and toolsets that provide tools in bulk.
Package tool defines the tools an Agent can call: the tool interface, the execution context, results, and toolsets that provide tools in bulk.
mcp
Package mcp exposes the tools of an MCP (Model Context Protocol) server as a toolset; add a Client to Agent.Toolsets to use it.
Package mcp exposes the tools of an MCP (Model Context Protocol) server as a toolset; add a Client to Agent.Toolsets to use it.
shell
Package shell provides the built-in command tool shell: the model can run a command in the foreground and get its output, or run it in the background and receive the result as a notice in the session when it ends.
Package shell provides the built-in command tool shell: the model can run a command in the foreground and get its output, or run it in the background and receive the result as a notice in the session when it ends.
skill
Package skill provides skills: focused instructions for the model, optionally with resource files.
Package skill provides skills: focused instructions for the model, optionally with resource files.
task
Package task provides the built-in background task tool task: it lists and stops the background tasks spawned by the current session, for every kind of task, including sub-agents and background commands.
Package task provides the built-in background task tool task: it lists and stops the background tasks spawned by the current session, for every kind of task, including sub-agents and background commands.
todo
Package todo provides the built-in checklist tool todo_write: the model breaks a multi-step task into a checklist and updates its progress as it goes.
Package todo provides the built-in checklist tool todo_write: the model breaks a multi-step task into a checklist and updates its progress as it goes.
x
notify
Package notify provides a common interface for sending Agent notifications.
Package notify provides a common interface for sending Agent notifications.
notify/telegram
Package telegram implements notify.Notifier with the Telegram Bot API.
Package telegram implements notify.Notifier with the Telegram Bot API.
notify/webhook
Package webhook implements notify.Notifier with an HTTP POST of a JSON body.
Package webhook implements notify.Notifier with an HTTP POST of a JSON body.

Jump to

Keyboard shortcuts

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