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//! - `mcp-server` - Built-in MCP server exposing flow-editing tools over streamable HTTP
40//! - `test-utils` - Testing utilities including TestProbeAgent
41
42mod agent;
43mod config;
44mod context;
45mod definition;
46mod error;
47mod external_agent;
48mod id;
49mod message;
50mod modular_agent;
51mod output;
52mod preset;
53mod registry;
54mod runtime;
55mod spec;
56mod value;
57
58#[cfg(feature = "llm")]
59pub mod llm;
60#[cfg(feature = "llm")]
61pub mod session;
62pub mod tool;
63
64#[cfg(feature = "mcp")]
65pub mod mcp;
66
67#[cfg(feature = "mcp-server")]
68pub mod mcp_server;
69
70#[cfg(feature = "test-utils")]
71pub mod test_utils;
72
73// re-export async_trait
74pub use async_trait::async_trait;
75
76// re-export photon_rs
77#[cfg(feature = "image")]
78pub use photon_rs::{self, PhotonImage};
79
80// re-export im
81pub use im;
82
83// re-export CancellationToken (used by AgentContext and ModularAgent cancellation APIs)
84pub use tokio_util::sync::CancellationToken;
85
86// re-export inventory
87pub use inventory;
88
89// re-export FnvIndexMap
90pub use fnv;
91pub use indexmap;
92pub type FnvIndexMap<K, V> = indexmap::IndexMap<K, V, fnv::FnvBuildHasher>;
93pub type FnvIndexSet<T> = indexmap::IndexSet<T, fnv::FnvBuildHasher>;
94
95// Re-export the crate under its canonical name for proc-macros.
96pub extern crate self as modular_agent_core;
97
98// Re-exports modular_agent_macros
99pub use modular_agent_macros::modular_agent;
100
101pub use agent::{Agent, AgentData, AgentStatus, AsAgent, HasAgentData, new_agent_boxed};
102pub use config::{AgentConfigs, AgentConfigsMap};
103pub use context::AgentContext;
104pub use definition::{AgentConfigSpec, AgentConfigSpecs, AgentDefinition, AgentDefinitions};
105pub use error::AgentError;
106#[cfg(feature = "llm")]
107pub use llm::{
108 ContentBlock, Message, MessageContent, MessageEvent, ToolCall, ToolCallFunction, Usage,
109 estimate_context_tokens, estimate_message_tokens,
110};
111pub use modular_agent::{EventEnvelope, ModularAgent, ModularAgentEvent, SharedAgent};
112pub use output::AgentOutput;
113pub use preset::{Preset, PresetInfo};
114pub use registry::AgentRegistration;
115#[cfg(feature = "llm")]
116pub use session::{
117 InMemorySessionStore, JsonlSessionStore, SessionEntry, SessionMeta, SessionStore, build_context,
118};
119pub use spec::{AgentSpec, ConnectionSpec, PresetSpec, PresetSpecs};
120pub use value::{AgentValue, AgentValueMap};