NenjoNenjo Docs
Harness

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 methodPurpose
with_manifestProvide a complete manifest directly
with_loaderLoad a partial manifest from a source such as the platform cache or a custom loader
with_model_factoryMap manifest provider names like openai, anthropic, gemini, or ollama to model clients
with_tool_factoryBuild the tools available to each agent based on its manifest
with_knowledge_packsRegister Library, package, or local knowledge packs as searchable source material
with_memoryAdd memory tools and prompt memory summaries
with_agent_configSet 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 methodWhat it changes
with_project_contextInjects project variables and project-scoped memory
with_routine_contextAdds routine-level template variables
with_step_contextAdds current step template variables during routine execution
with_work_dirScopes file, shell, and git tools to a project worktree
with_toolAdds an extra tool for this runner
with_memory_scopeRestores 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 typeRole
ManifestLoaderLoads a full or partial Manifest
ModelProviderFactoryCreates model providers by manifest model_provider name
ToolFactoryCreates an agent's runtime tools from platform scopes, abilities, MCP assignments, and config
MemoryStores and recalls memories and resources
AgentRunnerExecutes chat turns and streams turn events
RoutineRunnerExecutes a manifest routine by ID
TurnEventDescribes tool calls, delegation, transcript updates, pause/resume, compaction, and completion

Public Modules

ModulePurpose
agentsAgent builder, instance, runner, prompts, abilities, domains, and delegation
manifestTyped platform resource definitions and manifest loading
providerProvider builder, model factory, tool factory, agent lookup, and routine lookup
memoryMemory traits, markdown memory, memory scopes, and memory tools
contextPrompt rendering and project/routine/step template variables
routinesRoutine execution, gates, councils, step results, and routine events
knowledgeKnowledge pack registration and source-material tools

On this page