Cognitive Architectures for Multi-Agent Teams.
- Overview
- Key Features
- Installation
- Quick Start
- Core Components
- Language Models and Providers
- Tools
- Multi-Agent Teams
- Documentation
- Contributing
- License
- Acknowledgments
- Support
Mainframe-Orchestra is a lightweight, open-source agentic framework for building LLM-based pipelines and multi-agent teams. It implements a unique approach to agent orchestration that goes beyond simple routing, enabling complex workflows.
- Modularity: Modular architecture for easy building, extension, and integration
- Agent Orchestration: Agents can act as both executors and conductors, enabling dynamic task decomposition and coordination among agents
- Phased Task Execution: Reduces cognitive load on LLMs through structured thinking patterns
- Tool Integration: Simple docstring-based tool definitions without complex JSON schemas
- Streaming Support: Real-time output streaming with both sync and async support
- Built-in Fallbacks: Graceful handling of LLM failures with configurable fallback chains
Install Orchestra using pip:
pip install mainframe-orchestra
Here's a simple example to get you started:
from mainframe_orchestra import Agent, Task, OpenaiModels, WebTools, set_verbosity
set_verbosity(1)
research_agent = Agent(
agent_id="research_assistant_1",
role="research assistant",
goal="answer user queries",
llm=OpenaiModels.gpt_4o,
tools={WebTools.exa_search}
)
def research_task(topic):
return Task.create(
agent=research_agent,
instruction=f"Use your exa search tool to research {topic} and explain it in a way that is easy to understand.",
)
result = research_task("quantum computing")
print(result)
Tasks: Discrete units of work
Agents: Personas that perform tasks and can be assigned tools
Tools: Wrappers around external services or specific functionalities
Language Model Interfaces: Consistent interface for various LLM providers
Orchestra supports a wide range of language models from a number of providers:
GPT-4o, GPT-4o Mini, & Custom defined models
Claude 3 Haiku, Claude 3 Sonnet, Claude 3 Opus, Claude 3.5 Sonnet, & Custom defined models
GPT-4 Turbo, Claude 3 Opus, Mixtral 8x7B, Llama 3.1 405B, & Custom defined models
Mistral, Mixtral, Llama 3.1, Qwen, Gemma, & Custom defined models
Mixtral 8x7B, Llama 3, Llama 3.1, Gemma, & Custom defined models
Custom defined models
Gemini 1.5 Flash, Gemini 1.5 Flash 8B, Gemini 1.5 Pro, & Custom defined models
Deepseek Reasoner, Deepseek Chat, & Custom defined models
Each provider is accessible through a dedicated class (e.g., OpenaiModels
, AnthropicModels
, etc.) with methods corresponding to specific models. This structure allows for painless switching between models and providers, enabling users to leverage the most suitable LLM for their tasks.
Mainframe-Orchestra comes with a comprehensive set of built-in tools that provide various functionalities for your agents. Here's an overview of the available tool categories:
- FileTools: Read and write CSV, JSON, XML, and other file formats
- TextSplitters: Tools for chunking and splitting text documents
- EmbeddingsTools: Generate embeddings for text content
- FaissTools: Vector storage and similarity search operations
- PineconeTools: Vector database operations with Pinecone
- WebTools: Web scraping, searches, and data retrieval (Serper, Exa, etc.)
- WikipediaTools: Search and retrieve Wikipedia content
- AmadeusTools: Flight information and travel data
- GitHubTools: GitHub repository operations and content access
- LinearTools: Linear API-based tools for creating, updating, and retrieving tasks
- YahooFinanceTools: Stock market data and financial analysis
- FredTools: Federal Reserve Economic Data access
- CalculatorTools: Date, time, and mathematical calculations
- MatplotlibTools: Data visualization and plotting
- AudioTools: Audio processing and manipulation
- TextToSpeechTools: Text-to-speech conversion using ElevenLabs and OpenAI APIs
- WhisperTools: Audio transcription and translation using OpenAI's Whisper API
- LangchainTools: Wrapper for accessing the Langchain tools ecosystem
Mainframe-Orchestra supports creating custom tools to extend functionality beyond the built-in tools. Custom tools can be implemented either as static methods or as class instance methods for more complex operations. Here's a basic example:
import numpy as np
from typing import List, Union
class NumpyTools:
@staticmethod
def array_mean(arr: Union[List[float], np.ndarray]) -> Union[float, str]:
"""
Calculate the mean of a given array.
Args:
arr (Union[List[float], np.ndarray]): Input array or list of numbers.
Returns:
Union[float, str]: The mean of the input array as a float, or an error message as a string.
"""
try:
arr = np.array(arr, dtype=float)
if arr.size == 0:
return "Error: Input array is empty."
return float(np.mean(arr))
except TypeError as e:
return f"Error: Invalid input type. Expected a list or numpy array of numbers. Details: {e}"
except Exception as e:
return f"Error: An unexpected error occurred: {e}"
Tools can be assigned to agents during initialization:
agent = Agent(
agent_id="my_agent",
tools={NumpyTools.array_mean, WebTools.exa_search}
)
For detailed documentation on creating custom tools, including best practices for error handling and API integration, visit our Custom Tools Documentation.
Mainframe-Orchestra allows you to create multi-agent teams that can use tools to complete a series of tasks. Here's an example of a finance agent that uses multiple agents to analyze a stock:
from mainframe_orchestra import Task, Agent, Conduct, OpenaiModels, WebTools, YahooFinanceTools
# Create specialized agents
market_analyst = Agent(
agent_id="market_analyst",
role="Market Microstructure Analyst",
goal="Analyze market microstructure and identify trading opportunities",
attributes="You have expertise in market microstructure, order flow analysis, and high-frequency data.",
llm=OpenaiModels.gpt_4o,
tools={YahooFinanceTools.calculate_returns, YahooFinanceTools.get_historical_data}
)
fundamental_analyst = Agent(
agent_id="fundamental_analyst",
role="Fundamental Analyst",
goal="Analyze company financials and assess intrinsic value",
attributes="You have expertise in financial statement analysis, valuation models, and industry analysis.",
llm=OpenaiModels.gpt_4o,
tools={YahooFinanceTools.get_financials, YahooFinanceTools.get_ticker_info}
)
technical_analyst = Agent(
agent_id="technical_analyst",
role="Technical Analyst",
goal="Analyze price charts and identify trading patterns",
attributes="You have expertise in technical analysis, chart patterns, and technical indicators.",
llm=OpenaiModels.gpt_4o,
tools={YahooFinanceTools.get_historical_data}
)
sentiment_analyst = Agent(
agent_id="sentiment_analyst",
role="Sentiment Analyst",
goal="Analyze market sentiment, analyst recommendations and news trends",
attributes="You have expertise in market sentiment analysis.",
llm=OpenaiModels.gpt_4o,
tools={YahooFinanceTools.get_recommendations, WebTools.serper_search}
)
conductor_agent = Agent(
agent_id="conductor_agent",
role="Conductor",
goal="Conduct the orchestra",
attributes="You have expertise in orchestrating the agents in your team.",
llm=OpenaiModels.gpt_4o,
tools=[Conduct.conduct_tool(market_analyst, fundamental_analyst, technical_analyst, sentiment_analyst)]
)
def chat_task(conversation_history, userinput):
return Task.create(
agent=conductor_agent,
messages=conversation_history,
instruction=userinput
)
def main():
conversation_history = []
while True:
userinput = input("You: ")
conversation_history.append({"role": "user", "content": userinput})
response = chat_task(conversation_history, userinput)
conversation_history.append({"role": "assistant", "content": response})
print(f"Market Analyst: {response}")
if __name__ == "__main__":
main()
Note: this example requires the yahoofinance and yfinance packages to be installed. You can install them with pip install yahoofinance yfinance
.
The Conduct
and Compose
tools are used to orchestrate and compose agents. Conduct is used to actually instruct and orchestrate a team of agents, while Compose is used in addition to the Conduct tool to enrich the orchestration process with additional complexity as a preprocessing step. It's important to note that Conduct is required for the orchestration process to work, while Compose is an optional additional tool that can be used to enrich the orchestration process.
By combining agents, tasks, tools, and language models, you can create a wide range of workflows, from simple pipelines to complex multi-agent teams.
For more detailed information, tutorials, and advanced usage, visit our documentation.
Mainframe-Orchestra depends on and welcomes community contributions! Please review contribution guidelines and submit a pull request if you'd like to contribute.
Mainframe-Orchestra is released under the Apache License 2.0. See the LICENSE file for details.
Orchestra is a fork and further development of TaskflowAI.
For issues or questions, please file an issue on our GitHub repository issues page.
⭐️ If you find Mainframe-Orchestra helpful, consider giving it a star!
Happy building!