Installation
Quick Start
use ReadFileTool;
use Agent;
async
Use Cases
Example projects built with agentwerk:
- Terminal REPL: minimal interactive chat
- Divide and Conquer: arithmetic problem shared across agents
- Deep Research: deep research pipeline (requires
BRAVE_API_KEY) - Malware Scanner: identify indicators of compromise in a software package
Configure an LLM provider first (see Environment).
API
- Agents: Workers that pick up tickets and produce results.
- Prompting: Role, context, and task shaping the work of an agent.
- Tickets: Ticket system allowing to orchestrate complex work.
- Tools: Capabilities agents use to solve a ticket.
- Knowledge: Knowledge base an agent creates during a run.
- Schemas: Schemas for validating ticket results.
- Events: Lifecycle events emitted while agents work.
- Stats: Metrics about tickets, tokens and time.
Agents
An Agent picks up tickets, uses assigned tools to solve them, and writes the result back onto each ticket.
use ReadFileTool;
let agent = new
.name
.label
.tool
| Method | Description |
|---|---|
name(s) |
Set an identifier for assigning tickets. |
label(l) / labels([..]) |
Restrict the agent to tickets carrying matching labels. |
tool(t) / tools([..]) |
Register a tool the agent may call. |
dir(p) |
Set the directory accessible for tool calls. |
Providers
A Provider connects the agent to an LLM service. agentwerk ships providers for Anthropic, OpenAI, Mistral, and a LiteLLM proxy.
use AnthropicProvider;
let agent = new
.provider
.model;
// Or pick from environment variables (see Environment).
let agent = new
.provider_from_env
.model_from_env;
Each provider exposes .base_url(url) and .timeout(duration) to override the endpoint and request timeout.
| Method | Description |
|---|---|
provider(p) |
Set the LLM provider. |
provider_from_env() |
Detect the provider from environment variables. |
model(m) |
Set the model the provider runs. |
model_from_env() |
Read the model name from environment variables. |
Prompting
Every prompt has three parts: role (who the agent is), context (the situation it operates in), and task (work it should perform). The structure follows the prompting guide.
let agent = new
.role
.context
.task;
When context(...) is not set, agentwerk supplies a default block:
- -------
Tickets
The TicketSystem is the core data structure of agentwerk to orchestrate complex collaboration between agents. A task is the work itself, a ticket wraps it with additional metadata, like labels and schemas. Labels route work to matching agents.
use ;
let tickets = new;
tickets.agent;
tickets.agent;
tickets.task_labeled;
let report = new
.label
.schema;
tickets.ticket;
| Method | Description |
|---|---|
agent(agent) |
Register an agent with the system. |
dir(d) |
Set the directory where knowledge, results, and ticket logs are persisted. |
task(t) |
Submit a task. |
task_labeled(t, l) |
Submit a task tagged with l for label-scoped routing. |
task_schema(t, s) |
Submit a task whose result must validate against s. |
task_schema_labeled(t, s, l) |
Submit a labeled task with a result schema. |
ticket(t) |
Submit a caller-built Ticket. |
Execution
Start executing tickets with run calls:
let running = tickets.run; // returns immediately
let results = tickets.run_dry.await; // waits for the queue to empty
| Method | Description |
|---|---|
run() |
Begin processing tickets in the background. The caller can observe progress, submit more tickets, or stop the run while agents work. |
run_dry().await |
Begin processing tickets and block until the queue is empty. Returns all collected TicketResults once agents stop. |
interrupt_signal(s) |
Signal allowing to stop every agent and tool execution. |
Policies
Configure execution policies on a ticket system. A breach fires EventKind::PolicyViolated and halts execution.
let tickets = new
.max_steps
.max_time
.max_input_tokens
.max_output_tokens
.max_request_tokens
.max_schema_retries
.max_request_retries
.request_retry_delay;
| Method | Description |
|---|---|
max_steps(n) |
Cap the total number of steps. |
max_time(d) |
Cap the total elapsed duration. |
max_input_tokens(n) |
Cap the total input tokens. |
max_output_tokens(n) |
Cap the total output tokens. |
max_request_tokens(n) |
Cap the input tokens per request. |
max_schema_retries(n) |
Cap the schema-validation retry attempts. |
max_request_retries(n) |
Cap the retry attempts on recoverable provider errors. |
request_retry_delay(d) |
Set the base delay between request retries. |
Tools
Give agents access to tools helping them to solve a given task. agentwerk provides minimal baseline tools:
| Tool | Description | |
|---|---|---|
| File | ReadFileTool |
Reads a file with line numbers, offset, and limit. |
WriteFileTool |
Creates or overwrites a file. | |
EditFileTool |
Replaces text in a file. | |
| Search | GlobTool |
Finds files by pattern. |
GrepTool |
Searches file contents. | |
ListDirectoryTool |
Lists files and directories. | |
| Shell | BashTool |
Runs shell commands matching an allowed pattern. |
| Web | WebFetchTool |
Fetches a URL and returns its body. |
| Tickets | WriteResultTool |
Writes the agent's result for the current ticket and marks it done. |
ManageTicketsTool |
Reads the ticket queue and creates or edits tickets. | |
ReadTicketsTool |
Reads the ticket queue. | |
WriteTicketsTool |
Creates or edits tickets in the queue. | |
| Knowledge | KnowledgeTool |
Writes, reads, removes, or lists pages in the agent's knowledge store. |
| Discovery | ToolSearchTool |
Discovers tools registered with Tool::defer(true). |
Custom tools
Define custom tools for specific needs. Each tool declares a JSON-Schema for its inputs:
use ;
use json;
let greet = new
.schema
.read_only
.handler;
.read_only(true) allows the agent to run a tool concurrently with other read-only calls in the same step.
Knowledge
A Knowledge store is the agent's long-term memory. It is written to disk, can be shared across multiple agents, and is curated by the agent through KnowledgeTool.
use Knowledge;
// Override default knowledge path:
let agent = new.knowledge;
// Or share one store across multiple agents:
let store = open?;
let alice = new.knowledge;
let bob = new.knowledge;
| Method | Description |
|---|---|
knowledge(into) |
Set the knowledge store path. |
Schemas
A Schema constrains the result an agent must produce for a ticket. A violation triggers a retry until max_schema_retries is exhausted.
use Schema;
let schema = parse?;
tickets.task_schema;
Events
Events report everything that happens while your agents work and give you deep insights into behavior or failures.
use Arc;
use ;
let agent = new
.event_handler;
| Kind | Description | |
|---|---|---|
| Ticket | TicketStarted |
An agent claimed a ticket. |
TicketDone |
A ticket finished successfully. | |
TicketFailed |
A ticket failed. | |
| Provider | RequestStarted |
A provider request started. |
RequestFinished |
A provider request finished and reported its token usage. | |
RequestFailed |
A provider request failed and stopped the ticket. | |
TextChunkReceived |
A streamed text chunk arrived. | |
| Tool | ToolCallStarted |
A tool invocation started. |
ToolCallFinished |
A tool invocation finished. | |
ToolCallFailed |
A tool invocation failed but the ticket continues. | |
| Run | PolicyViolated |
A policy limit was breached and execution stopped. |
Stats
Stats contain metrics about the progress of your agents' work, allowing to optimize your agentic system and identify bottlenecks.
let s = tickets.stats;
let scan = s.stats_for_label;
| Method | Description | |
|---|---|---|
| Run | run_duration() |
Return the run's elapsed duration, live while agents work and frozen once the loop finishes. None until the first ticket starts. |
| Work | work_duration() |
Return the sum of every finished ticket's start-to-end span. |
avg_work_duration() |
Return the mean of the same span, or None until a ticket finishes. |
|
| Tickets | tickets_created() |
Return the count of tickets created. |
tickets_done() |
Return the count of tickets that finished successfully. | |
tickets_failed() |
Return the count of tickets that failed. | |
tickets_success_rate() |
Return done / (done + failed), or None until a ticket finishes. |
|
ticket_duration() |
Return the sum of every finished ticket's creation-to-end span. | |
avg_ticket_duration() |
Return the mean of the same span, or None until a ticket finishes. |
|
| Tokens | input_tokens() |
Return the total input tokens across all provider responses. |
output_tokens() |
Return the total output tokens across all provider responses. | |
| Activity | steps() |
Return the count of times an agent picked up a ticket to process. |
requests() |
Return the total provider responses received. | |
tool_calls() |
Return the total tool calls. | |
errors() |
Return the total provider errors. | |
| Labels | stats_for_label(label) |
Return a nested Stats slice scoped to tickets carrying label. |
Development
Workspace
crates/agentwerk/: the library.crates/use-cases/: runnable example binaries that depend on the library.
Building and testing
Integration tests
Configure an LLM provider first (see Environment).
Use cases
Publishing
GitHub Actions handles the crates.io publish via trusted publishing once the new tag is pushed (git push --tags).
Documentation
LiteLLM proxy
Start a local LiteLLM proxy on port 4000 that forwards to a provider. Requires Docker.
Local inference servers
agentwerk relies on server-side tool calling. Enable it through the following flags:
| Server | Flag |
|---|---|
| vLLM | --enable-auto-tool-choice --tool-call-parser <parser> |
| llama.cpp | --jinja (enables tool calling) |
Environment
Use cases and integration tests use the following environment variables:
General
| Variable | Description |
|---|---|
MODEL |
Generic model override for model_from_env(). |
BRAVE_API_KEY |
Required by the deep-research example. |
Anthropic
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
API key (required) |
ANTHROPIC_BASE_URL |
API URL (default: https://api.anthropic.com) |
ANTHROPIC_MODEL |
Model (default: claude-sonnet-4-20250514) |
Mistral
| Variable | Description |
|---|---|
MISTRAL_API_KEY |
API key (required) |
MISTRAL_BASE_URL |
API URL (default: https://api.mistral.ai) |
MISTRAL_MODEL |
Model (default: mistral-medium-2508) |
OpenAI
| Variable | Description |
|---|---|
OPENAI_API_KEY |
API key (required) |
OPENAI_BASE_URL |
API URL (default: https://api.openai.com) |
OPENAI_MODEL |
Model (default: gpt-4o) |
LiteLLM proxy
| Variable | Description |
|---|---|
LITELLM_BASE_URL |
Proxy URL (default: http://localhost:4000) |
LITELLM_API_KEY |
Auth key (required to select via from_env()) |
LITELLM_MODEL |
Model (default: claude-sonnet-4-20250514) |
LITELLM_PROVIDER |
LLM provider (anthropic, mistral, openai, litellm): explicit selection that overrides API-key auto-detection. |