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;
36/// `long_term_memory` of the `agent` node (feature `memory`).
37#[cfg(feature = "memory")]
38pub(crate) mod memory;
39/// Reading facts out of saved notes for the memory graph (feature `memory-graph`).
40#[cfg(feature = "memory-graph")]
41pub mod memory_graph;
42/// Scripted model for tests and offline examples (feature `mock`, on by default).
43#[cfg(any(test, feature = "mock"))]
44pub mod mock;
45pub mod nodes;
46pub mod providers;
47pub mod registry;
48/// Record / replay provider for deterministic runs (feature `replay`).
49#[cfg(feature = "replay")]
50pub mod replay;
51pub mod sse;
52/// `subagents` of the `agent` node: workflows run as child runs (feature `subagents`).
53#[cfg(feature = "subagents")]
54pub(crate) mod subagents;
55/// Plain completions for work outside a run (feature `text-model`).
56#[cfg(feature = "text-model")]
57pub mod text_model;
58pub mod types;
59#[cfg(feature = "typesafe")]
60pub mod typesafe;
61#[cfg(any(feature = "memory", feature = "learning"))]
62pub(crate) mod user_scope;
63
64#[cfg(feature = "http")]
65mod http;
66#[cfg(feature = "http")]
67pub use http::prewarm_http_client;
68
69#[cfg(feature = "anthropic")]
70pub mod anthropic;
71#[cfg(feature = "bedrock")]
72pub mod bedrock;
73#[cfg(feature = "gemini")]
74pub mod gemini;
75#[cfg(feature = "openai")]
76pub mod openai;
77
78pub use error::LlmError;
79pub use registry::ModelRegistry;
80pub use types::{
81    ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
82    Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
83};
84
85/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
86pub fn register(registry: &mut graphrt_core::Registry) {
87    registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
88    registry.register_lazily_described(
89        "question-classifier",
90        nodes::descriptors::question_classifier,
91        nodes::classifier::factory,
92    );
93    registry.register_lazily_described(
94        "parameter-extractor",
95        nodes::descriptors::parameter_extractor,
96        nodes::extractor::factory,
97    );
98    registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
99    #[cfg(feature = "typesafe")]
100    registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
101}