Skip to main content

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.

IntroductionWhat Freyja is, what it is not, and why it exists
FeaturesWhat works today, and what does not
Getting startedInstall, set a key, make a call
ConceptsThe five ideas everything else follows from
Building an agentA short tutorial: a tool, an agent, a conversation, and what will bite you
Calling the model directlyThe 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.

ToolA function the model can call, written by hand or wrapping another tool
StorageWhere a conversation is kept between sends
MemoryWhat the model sees of a conversation on each send
TokenCounterHow many tokens a message costs, for windows with a token budget
ModelA model Freyja cannot reach over HTTP, or a wrapper around one
EmbedderText to vectors, from a local model or a service Freyja does not speak
HookCode that runs around every model call and tool call

Core concepts​

One guide for each part of Freyja you build with.

AgentsThe builder, parallel tool calls, the guard, the Run and why it stopped
ConversationsSending, streaming, what is stored, summaries and compaction
MemoryWindows, token budgets, summaries, and writing your own Memory
HooksCode that watches every model call and tool call, and can end a run
Human approvalPausing on Decision::Ask and resuming, even after a restart
Multi-agentAn agent as a tool, and a Team that hands a conversation over
Structured outputTyped answers from a schema
MediaImages in a prompt
ObservabilityTracing, the run span, token budgets and cost
TestingA scripted model, record and replay, and storage conformance

Providers​

Providers overviewBuilt-in versus custom, and how to choose
OpenAIResponses API
GeminiInteractions API
AnthropicMessages API
OpenAI Chat CompletionsThe format most third-party vendors speak
Custom providersReaching any endpoint Freyja does not ship

Reference​

Look these up rather than reading them through. Generated rustdoc is on docs.rs.

ClientClient, EndpointPreset, EndpointConfig, credentials, HTTP
RequestsGenerateRequest and every builder method
MessagesMessage, Role, InputContent
Tools#[tool], Tool, ToolDefinition, dispatch, and the full round trip
StorageStorage, Memory, Conversation, and where a conversation lives between calls, in memory or in a file
ResponsesGenerateResponse, OutputContent, ResponseStatus, Usage
StreamingClient::stream, EventStream, StreamEvent, into_response
ErrorsError 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.

ArchitectureHow the crate is laid out and why
Capability modelWhat Freyja may decide on a vendor's behalf, and why it is almost nothing
Adding a dialectImplementing 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.