Skip to main content

Crate nano_agent

Crate nano_agent 

Source
Expand description

Structured LLM agents in Rust: JSON-schema input/output, system prompt building, optional chat history, context providers, and optional tools. Backed by genai (e.g. Gemini with JSON response format).

§Features

FeaturePurpose
searxngSearXNG search tool
calculatorExpression evaluation tool
webpage_scraperFetch and simplify web pages

§Example

use nano_agent::{
    AgentConfig, BasicChatInputSchema, BasicNanoAgent, NanoAgent,
    context::{ChatHistory, SystemPromptGenerator},
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, JsonSchema)]
struct Out {
    chat_message: String,
}

let mut agent = BasicNanoAgent::<BasicChatInputSchema, Out>::new(
    AgentConfig::new("gemini-2.5-flash-lite")
        .with_system_prompt_generator(SystemPromptGenerator::new())
        .with_chat_history(ChatHistory::new()),
);
let _reply: Out = agent
    .run(BasicChatInputSchema {
        chat_message: "Hello".into(),
    })
    .await?;

Re-exports§

pub use genai;

Modules§

context
tools

Structs§

AgentConfig
Agent configuration.
AgentInner
Inner agent state.
BasicChatInputSchema
Basic chat input schema.
BasicChatOutputSchema
Basic chat output schema.
BasicNanoAgent
Wraps AgentInner and implements NanoAgent with no extra state or hooks.

Enums§

AgentError
Agent error.

Traits§

NanoAgent
Schema-driven chat agent: system prompt, optional history, structured I/O.

Attribute Macros§

async_trait