Freyja documentation
A Rust library for talking to large language models, and for building agents on top of them. One request type, four wire formats, any compatible endpoint.
New here? Read Introduction, then Getting started.
Learn
Read these in order the first time. About twenty minutes end to end.
| Introduction | What Freyja is, what it is not, and why it exists |
| Features | What works today, and what does not |
| Getting started | Install, set a key, make a call |
| Concepts | The five ideas everything else follows from |
| Building an agent | A short tutorial: a tool, an agent, a conversation, and what will bite you |
| Calling the model directly | The low-level calls under Agent: one request, typed output, raw streams, your own loop |
Extending Freyja
Freyja's contracts are public, so a crate of your own can add a storage backend, a vector search, a local model or an exporter. Building on Freyja maps what you can build to the trait it implements, and covers publishing a crate. Each trait then has its own page, with its contract, a worked example and how to test it.
| Tool | A function the model can call, written by hand or wrapping another tool |
| Storage | Where a conversation is kept between sends |
| Memory | What the model sees of a conversation on each send |
| TokenCounter | How many tokens a message costs, for windows with a token budget |
| Model | A model Freyja cannot reach over HTTP, or a wrapper around one |
| Embedder | Text to vectors, from a local model or a service Freyja does not speak |
| Hook | Code that runs around every model call and tool call |
Core concepts
One guide for each part of Freyja you build with.
| Agents | The builder, parallel tool calls, the guard, the Run and why it stopped |
| Conversations | Sending, streaming, what is stored, summaries and compaction |
| Memory | Windows, token budgets, summaries, and writing your own Memory |
| Hooks | Code that watches every model call and tool call, and can end a run |
| Human approval | Pausing on Decision::Ask and resuming, even after a restart |
| Multi-agent | An agent as a tool, and a Team that hands a conversation over |
| Structured output | Typed answers from a schema |
| Media | Images in a prompt |
| Observability | Tracing, the run span, token budgets and cost |
| Testing | A scripted model, record and replay, and storage conformance |
Providers
| Providers overview | Built-in versus custom, and how to choose |
| OpenAI | Responses API |
| Gemini | Interactions API |
| Anthropic | Messages API |
| OpenAI Chat Completions | The format most third-party vendors speak |
| Custom providers | Reaching any endpoint Freyja does not ship |
Reference
Look these up rather than reading them through. Generated rustdoc is on docs.rs.
| Client | Client, EndpointPreset, EndpointConfig, credentials, HTTP |
| Requests | GenerateRequest and every builder method |
| Messages | Message, Role, InputContent |
| Tools | #[tool], Tool, ToolDefinition, dispatch, and the full round trip |
| Storage | Storage, Memory, Conversation, and where a conversation lives between calls, in memory or in a file |
| Responses | GenerateResponse, OutputContent, ResponseStatus, Usage |
| Streaming | Client::stream, EventStream, StreamEvent, into_response |
| Errors | Error and how to handle each variant |
Wire formats, for debugging an Api error against the native JSON: OpenAI, Chat Completions, Gemini, Anthropic.
Contributing
For working on Freyja itself rather than with it.
| Architecture | How the crate is laid out and why |
| Capability model | What Freyja may decide on a vendor's behalf, and why it is almost nothing |
| Adding a dialect | Implementing a new wire format |
Conventions
Samples assume these imports unless stated otherwise:
use freyja::{Client, GenerateRequest, Message, EndpointPreset, Role};
Samples that make a network call are written as if inside an async fn returning Result<(), freyja::Error>.
Status
Phases 0 through 2 are complete and Phase 3 has started. Typed tools, the provider-neutral round trip, streaming, and a conversation held between calls through Storage, with what the model sees chosen by a Memory on the agent, by turn group or by token budget, with a summary of what the window drops, and in a file that survives the process, are implemented. Hooks, approval, tracing, agents as tools and teams are implemented too, and retries remain deliberately caller-owned. Features has the honest boundary, and the roadmap has what is planned.