Skip to main content

graphrt_llm/
lib.rs

1//! # graphrt-llm
2//!
3//! Model providers and model-calling nodes for graphrt.
4//!
5//! - [`ChatModel`]: provider-neutral streaming chat interface.
6//! - [`openai`] (feature `openai`): any OpenAI-compatible endpoint.
7//! - [`anthropic`] (feature `anthropic`): the Anthropic Messages API.
8//! - [`ModelRegistry`]: named providers, registered as a host service.
9//! - Nodes: `llm`, `question-classifier`, `parameter-extractor` and `agent`
10//!   (a tool-calling loop over [`graphrt_core::tool::ToolRegistry`]).
11//!
12//! ```no_run
13//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
14//! let mut registry = graphrt_core::Registry::with_builtins();
15//! graphrt_llm::register(&mut registry);
16//! # #[cfg(feature = "http")]
17//! let models = graphrt_llm::ModelRegistry::from_env()?;
18//! # #[cfg(not(feature = "http"))]
19//! # let models = graphrt_llm::ModelRegistry::new();
20//! let services = graphrt_core::Services::new().with(models);
21//! # let _ = (registry, services);
22//! # Ok(())
23//! # }
24//! ```
25
26/// Keeping a conversation inside the model's context window (feature `context`).
27///
28/// Public only for the benchmark in `examples/context_bench.rs`, not a stable
29/// API: workflows use the `context_window` key of the `agent` and `llm` nodes.
30#[cfg(feature = "context")]
31#[doc(hidden)]
32pub mod context;
33pub mod credential_config;
34pub mod credentials;
35pub mod error;
36pub mod failover;
37/// `long_term_memory` of the `agent` node (feature `memory`).
38#[cfg(feature = "memory")]
39pub(crate) mod memory;
40/// Reading facts out of saved notes for the memory graph (feature `memory-graph`).
41#[cfg(feature = "memory-graph")]
42pub mod memory_graph;
43/// Scripted model for tests and offline examples (feature `mock`, on by default).
44#[cfg(any(test, feature = "mock"))]
45pub mod mock;
46pub mod nodes;
47pub mod providers;
48pub mod registry;
49/// Record / replay provider for deterministic runs (feature `replay`).
50#[cfg(feature = "replay")]
51pub mod replay;
52pub mod sse;
53/// `subagents` of the `agent` node: workflows run as child runs (feature `subagents`).
54#[cfg(feature = "subagents")]
55pub(crate) mod subagents;
56/// Plain completions for work outside a run (feature `text-model`).
57#[cfg(feature = "text-model")]
58pub mod text_model;
59pub mod types;
60#[cfg(feature = "typesafe")]
61pub mod typesafe;
62#[cfg(any(feature = "memory", feature = "learning"))]
63pub(crate) mod user_scope;
64
65#[cfg(feature = "http")]
66mod http;
67#[cfg(feature = "http")]
68pub use http::prewarm_http_client;
69
70#[cfg(feature = "anthropic")]
71pub mod anthropic;
72#[cfg(feature = "bedrock")]
73pub mod bedrock;
74#[cfg(feature = "gemini")]
75pub mod gemini;
76#[cfg(feature = "openai")]
77pub mod openai;
78
79pub use error::LlmError;
80pub use registry::ModelRegistry;
81pub use types::{
82    ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
83    Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
84};
85
86/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
87pub fn register(registry: &mut graphrt_core::Registry) {
88    registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
89    registry.register_lazily_described(
90        "question-classifier",
91        nodes::descriptors::question_classifier,
92        nodes::classifier::factory,
93    );
94    registry.register_lazily_described(
95        "parameter-extractor",
96        nodes::descriptors::parameter_extractor,
97        nodes::extractor::factory,
98    );
99    registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
100    #[cfg(feature = "typesafe")]
101    registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
102}