SDK API
The core Rust API for building providers, agents, routines, tools, memory, and streaming execution.
SDK API
The nenjo crate is the core SDK. It turns manifest resources into executable agents and routines.
The SDK is intentionally small at the top level. A caller supplies manifests, a model factory, tools, knowledge packs, and optional memory. The SDK handles prompt assembly, agent lookup, the turn loop, streaming events, delegation support, routine execution, knowledge tools, and memory tooling.
Provider
A Provider is the root runtime object. It owns a loaded Manifest plus the factories needed to create models and tools.
use nenjo::Provider;
let provider = Provider::builder()
.with_loader(my_manifest_loader)
.with_model_factory(my_model_factory)
.with_tool_factory(my_tool_factory)
.with_memory(my_memory)
.build()
.await?;The builder requires at least one manifest source and a model factory. If no tool factory is provided, agents run without external tools.
| Builder method | Purpose |
|---|---|
with_manifest | Provide a complete manifest directly |
with_loader | Load a partial manifest from a source such as the platform cache or a custom loader |
with_model_factory | Map manifest provider names like openai, anthropic, gemini, or ollama to model clients |
with_tool_factory | Build the tools available to each agent based on its manifest |
with_knowledge_packs | Register Library, package, or local knowledge packs as searchable source material |
with_memory | Add memory tools and prompt memory summaries |
with_agent_config | Set shared turn loop settings such as max iterations and parallel tool execution |
Multiple loaders are merged in order. This lets the worker combine platform manifests with local context sources.
Agents
Agents are resolved from the manifest by ID or name. The provider creates an AgentBuilder, then the builder produces an AgentRunner.
let runner = provider
.agent_by_name("coder")
.await?
.build()
.await?;
let output = runner.chat("Summarize the current project").await?;
println!("{}", output.text);An AgentBuilder can add execution context before build():
| Builder method | What it changes |
|---|---|
with_project_context | Injects project variables and project-scoped memory |
with_routine_context | Adds routine-level template variables |
with_step_context | Adds current step template variables during routine execution |
with_work_dir | Scopes file, shell, and git tools to a project worktree |
with_tool | Adds an extra tool for this runner |
with_memory_scope | Restores a previously resolved memory namespace |
Streaming
The SDK has both simple and streaming execution. Use chat() when only the final answer matters. Use chat_stream() when the caller needs tool events, transcript messages, pause/resume state, or completion output.
let mut handle = runner.chat_stream("Refactor the auth module").await?;
while let Some(event) = handle.recv().await {
match event {
nenjo::TurnEvent::ToolCallStart { calls, .. } => {
println!("starting {} tool call(s)", calls.len());
}
nenjo::TurnEvent::Done { .. } => break,
_ => {}
}
}
let output = handle.output().await?;TurnOutput contains the final text, token counts, tool call count, and messages that can be persisted as conversation history.
Routines
Routines are resolved from the same manifest and run through the provider.
let result = provider
.routine_by_id(routine_id)?
.run(task)
.await?;Use run_stream() for routine events and final output handling. Routine steps use the same provider-owned agent, model, tool, prompt, and memory machinery as normal agent runs.
Key Traits
| Trait or type | Role |
|---|---|
ManifestLoader | Loads a full or partial Manifest |
ModelProviderFactory | Creates model providers by manifest model_provider name |
ToolFactory | Creates an agent's runtime tools from platform scopes, abilities, MCP assignments, and config |
Memory | Stores and recalls memories and resources |
AgentRunner | Executes chat turns and streams turn events |
RoutineRunner | Executes a manifest routine by ID |
TurnEvent | Describes tool calls, delegation, transcript updates, pause/resume, compaction, and completion |
Public Modules
| Module | Purpose |
|---|---|
agents | Agent builder, instance, runner, prompts, abilities, domains, and delegation |
manifest | Typed platform resource definitions and manifest loading |
provider | Provider builder, model factory, tool factory, agent lookup, and routine lookup |
memory | Memory traits, markdown memory, memory scopes, and memory tools |
context | Prompt rendering and project/routine/step template variables |
routines | Routine execution, gates, councils, step results, and routine events |
knowledge | Knowledge pack registration and source-material tools |

