Multi-agent orchestration framework โ 3 modes, 100+ LLM providers, built-in tool calling & MCP
Project description
๐ Nexus
Multi-Agent Orchestration Framework for Python
3 orchestration modes ยท 100+ LLM providers ยท Built-in tool calling & MCP
Why Nexus?
Most agent frameworks force you to choose: simple API (Swarm) or powerful workflows (LangGraph). Nexus gives you both โ start with 5 lines of code, scale to complex DAG workflows, LLM-based routing, and self-organizing agent teams.
import asyncio
from nexus import Team
async def main():
async with Team(model="gpt-4o", api_key="sk-...") as team:
team.add_agent("coder", instructions="You write clean Python code.")
team.add_agent("writer", instructions="You write engaging articles.")
result = await team.run("Implement a binary search in Python")
print(result) # โ Automatically routed to 'coder'
asyncio.run(main())
โจ Highlights
| Feature | Description | |
|---|---|---|
| ๐ | 3 Orchestration Modes | Static Graph (DAG) ยท Dynamic Router (LLM triage) ยท Adaptive (embedding matching) |
| ๐ | 100+ LLM Providers | OpenAI, Anthropic, Groq, Deepseek, Mistral, Qwen, Ollama, Azure, Bedrock, Vertex AIโฆ via LiteLLM |
| ๐ง | Tool Calling | ReAct loop (Think โ Act โ Observe โ Repeat) with auto schema extraction from Python type hints |
| ๐ | Protocol-Native | MCP for tool servers ยท A2A for agent discovery |
| ๐ฌ | Multi-turn & Streaming | Conversation memory with chat() and real-time token streaming with stream() |
| ๐ก๏ธ | Production-Grade | Token budgets ยท Checkpoint/resume ยท Retry/fallback policies ยท Tracing ยท Metrics |
Installation
# Recommended โ unlocks 100+ LLM providers
pip install nexus-agents[litellm]
# Or pick a specific provider
pip install nexus-agents[openai] # OpenAI only
pip install nexus-agents[anthropic] # Anthropic only
# Everything (all providers + MCP + observability)
pip install nexus-agents[all]
Quick Start
Multi-Agent with Auto-Routing
import asyncio
from nexus import Team
async def main():
async with Team(model="gpt-4o", api_key="sk-...") as team:
team.add_agent("coder", instructions="You write Python code.")
team.add_agent("writer", instructions="You write articles.")
team.add_agent("analyst", instructions="You analyze data.")
# The router examines each task and picks the best agent
await team.run("Implement quicksort in Python") # โ coder
await team.run("Write a blog post about AI agents") # โ writer
asyncio.run(main())
Tool Calling (ReAct Loop)
Define tools as plain Python functions โ Nexus extracts the JSON schema automatically:
def calculate(expression: str) -> str:
"""Evaluate a math expression. Example: '2**32 - 1'"""
return str(eval(expression))
def get_current_time() -> str:
"""Get the current UTC time."""
from datetime import datetime, timezone
return datetime.now(timezone.utc).isoformat()
async with Team(model="gpt-4o", api_key="sk-...") as team:
team.add_agent(
"assistant",
instructions="Use tools to answer questions accurately.",
tools=[calculate, get_current_time],
)
result = await team.run("What is 2^32 - 1?")
# ๐ง Agent calls calculate("2**32 - 1") โ "4294967295"
# โจ Agent responds: "2ยณยฒ - 1 = 4,294,967,295"
Multi-turn Conversation
async with Team(model="gpt-4o", api_key="sk-...") as team:
team.add_agent("assistant", instructions="You are helpful.")
r1 = await team.chat("What is the Fibonacci sequence?")
r2 = await team.chat("Show me the first 10 numbers") # Remembers context
team.reset_conversation() # Clear history
Streaming Output
async with Team(model="gpt-4o", api_key="sk-...") as team:
team.add_agent("storyteller", instructions="You tell captivating stories.")
async for chunk in team.stream("Tell me a story about a time-traveling robot"):
print(chunk, end="", flush=True)
๐ More examples โ See the
examples/directory for runnable demos: tool calling, MCP integration, Graph/Router/Adaptive orchestration modes, and more.# Clone and run git clone https://github.com/songtianye/nexus.git && cd nexus pip install -e '.[all]' cp examples/.env.example examples/.env # Add your API key python examples/demo_tools.py simple # Try tool calling python examples/demo_modes.py graph # Try graph orchestration
Three Orchestration Modes
๐ท Graph โ Static DAG Workflows
For deterministic pipelines where you know the exact steps:
from nexus.orchestration.graph import GraphOrchestrator, START, END
graph = GraphOrchestrator()
graph.add_node("research", research_fn)
graph.add_node("write", write_fn)
graph.add_node("review", review_fn)
graph.add_edge(START, "research")
graph.add_edge("research", "write")
graph.add_edge("write", "review")
graph.add_conditional_edge(
"review",
lambda state: "write" if state.get("needs_revision") else END
)
result = await graph.execute({"topic": "AI Agents"})
๐ถ Router โ Dynamic LLM-Based Routing
A triage agent examines each request and picks the best specialist:
from nexus.orchestration.topology import TopologyMode
async with Team(model="gpt-4o", mode=TopologyMode.ROUTER) as team:
team.add_agent("coder", instructions="You write code.")
team.add_agent("writer", instructions="You write prose.")
await team.run("Implement quicksort in Python") # โ routes to coder
๐ด Adaptive โ Embedding-Based Capability Matching
Agents are matched to tasks via cosine similarity on capability vectors โ unique to Nexus:
from nexus import AgentCapability
from nexus.orchestration.topology import TopologyMode
async with Team(
model="gpt-4o",
mode=TopologyMode.ADAPTIVE,
embedding_model="text-embedding-3-small",
) as team:
team.add_agent("coder", capabilities=AgentCapability(coding=1.0, reasoning=0.8))
team.add_agent("writer", capabilities=AgentCapability(creativity=1.0, language=0.9))
await team.run("Write a poem about recursion") # โ capability match โ writer
100+ LLM Providers
Switch models by changing one string. Zero code changes:
Team(model="gpt-4o") # OpenAI
Team(model="anthropic/claude-sonnet-4-20250514") # Anthropic
Team(model="groq/llama-3.1-70b-versatile") # Groq (ultra-fast)
Team(model="deepseek/deepseek-chat") # Deepseek
Team(model="vertex_ai/gemini-1.5-pro") # Google Vertex AI
Team(model="bedrock/anthropic.claude-3-sonnet") # AWS Bedrock
Team(model="ollama/llama3.1") # Local (Ollama)
# Any OpenAI-compatible endpoint
Team(model="openai/my-model", api_base="https://my-api.com/v1", api_key="sk-...")
# Mix models per agent
async with Team(model="gpt-4o") as team:
team.add_agent("fast", model="groq/llama-3.1-70b-versatile") # Speed
team.add_agent("smart", model="anthropic/claude-sonnet-4-20250514") # Quality
Full list โ LiteLLM Providers
MCP Protocol Integration
Connect agents to any MCP tool server:
from nexus.protocol.mcp import MCPToolProvider
# Local MCP server via stdio
async with MCPToolProvider("npx", ["-y", "@modelcontextprotocol/server-filesystem", "."]) as mcp:
tools = await mcp.get_tools()
team.add_agent("file_agent", tools=tools)
# Remote MCP server via HTTP/SSE
async with MCPToolProvider(url="https://mcp-server.example.com/sse") as mcp:
tools = await mcp.get_tools()
team.add_agent("web_agent", tools=tools)
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Developer API โ
โ Team ยท CLI ยท @tool decorator ยท YAML config โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Observability โ
โ Distributed Tracing ยท Metrics ยท Token Accounting โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Orchestration โ
โ ๐ท Graph ยท ๐ถ Router ยท ๐ด Adaptive โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Runtime โ
โ Execution Engine ยท Checkpoint ยท Retry / Fallback โ
โ Token Budget ยท Auto-Degradation Strategies โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Protocol + Core โ
โ Agent ยท Task ยท Handoff ยท Message โ
โ A2A Protocol ยท MCP Protocol ยท Discovery Service โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Model Providers โ
โ OpenAI ยท Anthropic ยท Ollama ยท LiteLLM (100+) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Project Structure
nexus/
โโโ api.py # Team โ high-level API
โโโ cli.py # CLI: init / run / chat / inspect
โโโ core/ # Agent, Task, Handoff, Message, State
โโโ models/ # OpenAI, Anthropic, Ollama, LiteLLM providers
โโโ orchestration/ # Graph, Router, Adaptive, TopologyEngine
โโโ protocol/ # A2A, MCP, MessageBus, Discovery
โโโ runtime/ # Engine, Checkpoint, Budget, Policies
โโโ observability/ # Tracing, Metrics
How Nexus Compares
| Feature | Nexus | LangGraph | CrewAI | Swarm |
|---|---|---|---|---|
| Graph Workflows | โ | โ | โ | โ |
| Dynamic LLM Routing | โ | โ | โ ๏ธ | โ |
| Adaptive Matching | โ | โ | โ | โ |
| 100+ Providers (LiteLLM) | โ | โ | โ | โ |
| MCP Protocol | โ | โ | โ | โ |
| A2A Protocol | โ | โ | โ | โ |
| Tool Calling | โ | โ | โ | โ |
| Streaming | โ | โ | โ | โ |
| Token Budgets | โ | โ | โ | โ |
| Checkpoint / Resume | โ | โ | โ | โ |
| Minimal API (5 lines) | โ | โ | โ | โ |
Note: "โ" means not built-in. Some features may be available via plugins or custom code.
Roadmap
- Core primitives (Agent + Task + Handoff)
- 3 orchestration modes (Graph / Router / Adaptive)
- LiteLLM integration (100+ providers)
- Tool calling with ReAct loop
- MCP protocol integration
- A2A protocol support
- Streaming responses
- Multi-turn conversation
- Token budget management
- Checkpoint / resume
- Observability (tracing + metrics)
- CLI (init / run / chat / inspect)
- Agent memory (long-term RAG)
- OpenTelemetry export
- Web UI dashboard
- Multi-modal (vision, audio)
- Distributed execution
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
git clone https://github.com/songtianye/nexus.git
cd nexus
uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python -e ".[all,dev]"
.venv/bin/python tests/test_smoke.py # Verify everything works
License
MIT ยฉ 2025โ2026 Nexus Contributors
โญ If Nexus is useful to you, please star this repo โ it helps others discover it!
Examples ยท Issues ยท Discussions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nexus_agents-0.1.0.tar.gz.
File metadata
- Download URL: nexus_agents-0.1.0.tar.gz
- Upload date:
- Size: 249.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78c29db54e69e4946dc771c2230bafac876d8ac22b044b7ab12cc5b1738ee6b6
|
|
| MD5 |
1be6bcfebddaa68f2870f2d76a6fc288
|
|
| BLAKE2b-256 |
e122043f68f72ce4a5ba99db5b8c2e8b298a9b5b0e558f0ee4096fa88d00c322
|
File details
Details for the file nexus_agents-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nexus_agents-0.1.0-py3-none-any.whl
- Upload date:
- Size: 86.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
986f69ee04484da464a329da688559b627cc4309ecdb44b392262399076aee41
|
|
| MD5 |
51436e1f94452b0299a7e6be53f3db6d
|
|
| BLAKE2b-256 |
ee91594910cf49e312d6b62dbeabf8f0c9b47cd86bb0e94b6dd74d40d521767e
|