Skip to main content

modular_agent_core/
lib.rs

1#![recursion_limit = "256"]
2//! # Modular Agent Core
3//!
4//! A Rust framework for building modular multi-agent orchestration systems.
5//!
6//! This crate provides tools and abstractions to create, configure, and run agents
7//! in a stream-based architecture. It supports defining agent behaviors, managing
8//! agent flows, and handling agent input/output through a channel-based messaging system.
9//!
10//! ## Core Concepts
11//!
12//! ### ModularAgent
13//!
14//! [`ModularAgent`] is the central orchestrator that manages agent lifecycle, connections,
15//! and message routing. It maintains agent instances, connection maps, and handles events.
16//!
17//! ### Agents
18//!
19//! Agents are processing units that receive messages via channels and process them
20//! asynchronously. Implement the [`AsAgent`] trait to create custom agents, or use the
21//! `#[modular_agent]` macro for declarative agent definitions.
22//!
23//! ### Presets
24//!
25//! Presets are collections of agents and their connections, defined in JSON format.
26//! They can be loaded from files and managed via [`ModularAgent`] methods.
27//!
28//! ## Quick Start
29//!
30//! See the [CLI example](https://github.com/modular-agent/modular-agent-core/blob/main/examples/cli.rs)
31//! for a complete working example of loading a preset and running agents from the command line.
32//!
33//! ## Feature Flags
34//!
35//! - `file` - File handling support (enabled by default)
36//! - `image` - Image processing with photon-rs (enabled by default)
37//! - `llm` - LLM integration with Message/ToolCall types (enabled by default)
38//! - `mcp` - Model Context Protocol integration (enabled by default)
39//! - `test-utils` - Testing utilities including TestProbeAgent
40
41mod agent;
42mod config;
43mod context;
44mod definition;
45mod error;
46mod external_agent;
47mod id;
48mod message;
49mod modular_agent;
50mod output;
51mod preset;
52mod registry;
53mod runtime;
54mod spec;
55mod value;
56
57#[cfg(feature = "llm")]
58pub mod llm;
59#[cfg(feature = "llm")]
60pub mod session;
61pub mod tool;
62
63#[cfg(feature = "mcp")]
64pub mod mcp;
65
66#[cfg(feature = "test-utils")]
67pub mod test_utils;
68
69// re-export async_trait
70pub use async_trait::async_trait;
71
72// re-export photon_rs
73#[cfg(feature = "image")]
74pub use photon_rs::{self, PhotonImage};
75
76// re-export im
77pub use im;
78
79// re-export CancellationToken (used by AgentContext and ModularAgent cancellation APIs)
80pub use tokio_util::sync::CancellationToken;
81
82// re-export inventory
83pub use inventory;
84
85// re-export FnvIndexMap
86pub use fnv;
87pub use indexmap;
88pub type FnvIndexMap<K, V> = indexmap::IndexMap<K, V, fnv::FnvBuildHasher>;
89pub type FnvIndexSet<T> = indexmap::IndexSet<T, fnv::FnvBuildHasher>;
90
91// Re-export the crate under its canonical name for proc-macros.
92pub extern crate self as modular_agent_core;
93
94// Re-exports modular_agent_macros
95pub use modular_agent_macros::modular_agent;
96
97pub use agent::{Agent, AgentData, AgentStatus, AsAgent, HasAgentData, new_agent_boxed};
98pub use config::{AgentConfigs, AgentConfigsMap};
99pub use context::AgentContext;
100pub use definition::{AgentConfigSpec, AgentConfigSpecs, AgentDefinition, AgentDefinitions};
101pub use error::AgentError;
102#[cfg(feature = "llm")]
103pub use llm::{
104    ContentBlock, Message, MessageContent, MessageEvent, ToolCall, ToolCallFunction, Usage,
105    estimate_context_tokens, estimate_message_tokens,
106};
107pub use modular_agent::{ModularAgent, ModularAgentEvent, SharedAgent};
108pub use output::AgentOutput;
109pub use preset::{Preset, PresetInfo};
110pub use registry::AgentRegistration;
111#[cfg(feature = "llm")]
112pub use session::{
113    InMemorySessionStore, JsonlSessionStore, SessionEntry, SessionMeta, SessionStore, build_context,
114};
115pub use spec::{AgentSpec, ConnectionSpec, PresetSpec, PresetSpecs};
116pub use value::{AgentValue, AgentValueMap};