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
62#[cfg(feature = "http")]
63mod http;
64#[cfg(feature = "http")]
65pub use http::prewarm_http_client;
66
67#[cfg(feature = "anthropic")]
68pub mod anthropic;
69#[cfg(feature = "bedrock")]
70pub mod bedrock;
71#[cfg(feature = "gemini")]
72pub mod gemini;
73#[cfg(feature = "openai")]
74pub mod openai;
75
76pub use error::LlmError;
77pub use registry::ModelRegistry;
78pub use types::{
79    ChatDelta, ChatModel, ChatRequest, ChatResponse, ChatStream, ContentPart, FinishReason, InvalidToolArguments,
80    Message, ResponseFormat, Role, ToolCall, ToolChoice, collect,
81};
82
83/// Register the `llm`, `question-classifier`, `parameter-extractor` and `agent` node kinds.
84pub fn register(registry: &mut graphrt_core::Registry) {
85    registry.register_lazily_described("llm", nodes::descriptors::llm, nodes::llm::factory);
86    registry.register_lazily_described(
87        "question-classifier",
88        nodes::descriptors::question_classifier,
89        nodes::classifier::factory,
90    );
91    registry.register_lazily_described(
92        "parameter-extractor",
93        nodes::descriptors::parameter_extractor,
94        nodes::extractor::factory,
95    );
96    registry.register_lazily_described("agent", nodes::descriptors::agent, nodes::agent::factory);
97    #[cfg(feature = "typesafe")]
98    registry.register_lazily_described("system-one", nodes::descriptors::system_one, nodes::system_one::factory);
99}