Skip to main content

Crate sgr_agent

Crate sgr_agent 

Source
Expand description

§sgr-agent — LLM client + agent framework

Pure Rust. No dlopen, no external binaries. Works on iOS, Android, WASM — anywhere reqwest+rustls compiles.

§LLM Client (default)

  • Structured output — response conforms to JSON Schema (SGR envelope)
  • Function calling — tools as typed structs, model picks & fills params
  • Flexible parser — extract JSON from markdown, broken JSON, streaming chunks
  • Backends: Gemini (Google AI + Vertex AI), OpenAI (+ OpenRouter, Ollama)

§Agent Framework (feature = "agent")

  • Tool trait — define tools with typed args + async execute
  • ToolRegistry — ordered collection, case-insensitive lookup, fuzzy resolve
  • Agent trait — decides what tools to call given conversation history
  • 3 agent variants: SgrAgent (structured output), ToolCallingAgent (native FC), FlexibleAgent (text parse)
  • Agent loop — decide → execute → feed back, with 3-tier loop detection
  • Progressive discovery — filter tools by relevance (TF-IDF scoring)

Re-exports§

pub use coerce::coerce_value;
pub use flexible_parser::parse_flexible;
pub use flexible_parser::parse_flexible_coerced;
pub use schema::json_schema_for;
pub use schema::response_schema_for;
pub use tool::tool;
pub use tool::ToolDef;
pub use types::*;

Modules§

baml_parser
Lightweight BAML parser — extracts classes, enums, functions from .baml files.
benchmark
Benchmark suite: 5 fixed tasks to measure agent quality.
codegen
Code generator: BAML AST → Rust source code with schemars + serde derives.
coerce
Fuzzy type coercion for LLM outputs.
evolution
Self-evolution: agent evaluates its own runs and proposes improvements.
flexible_parser
Flexible JSON parser — extracts structured data from messy LLM output.
gemini
Gemini API client — structured output + function calling.
openai
OpenAI-compatible API client — works with OpenAI, OpenRouter, Ollama.
openapi
OpenAPI → Agent Tool: convert any API spec into a searchable, callable tool.
schema
JSON Schema generation from Rust types via schemars.
tool
Tool definitions — typed Rust structs → function declarations for LLM APIs.
types