A powerful framework for orchestrating multiple AI agents to work together efficiently
Project description
🤖 SmolagentsCrew
Orchestrate your AI dream team! 🚀 A framework built on top of smolagents from Hugging Face that brings multiple AI agents together to collaborate efficiently through smart threading and dependency management.
SmolagentsCrew serves as an orchestration layer that allows you to coordinate multiple smolagents, enabling them to work together on complex tasks while handling dependencies, parallel execution, and context sharing automatically.
✨ Features
- 🔄 Concurrent Task Execution: Watch your agents work in parallel with efficient threading
- 🔗 Smart Dependency Management: Let your tasks flow naturally with automatic dependency handling
- 🌐 Context Sharing: Seamless data sharing between tasks through an intelligent context system
- 🏗️ Flexible Agent Configuration: Build your perfect crew using our intuitive builder pattern
- 📝 Template-based Prompts: Create dynamic, context-aware prompts with variable substitution
📦 Installation
Currently, you can install SmolagentsCrew locally from the repository:
git clone https://github.com/antunsz/smolagents-crew.git
cd smolagents-crew
pip install -e .
🔥 Coming Soon: SmolagentsCrew will be available on PyPI! Stay tuned for a simpler installation via
pip install smolagents-crew
🚀 Quick Start
import os
from smolagents_crew import Agent, Task, Crew, TaskDependency
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
#you need to set your OPENAI_API_KEY var in you env
os.environ['OPENAI_API_KEY']=<sk-your_key>
# Create your AI dream team! 🤖
agent1 = Agent("research", agent_instance=CodeAgent, model=OpenAIServerModel('gpt-4o-mini'), tools=[DuckDuckGoSearchTool()])
agent2 = Agent("writer", agent_instance=CodeAgent, model=OpenAIServerModel('gpt-4o-mini'), tools=[DuckDuckGoSearchTool()])
# Define their missions with smart dependencies 📋
task1 = Task(
name="research_topic",
agent=agent1,
prompt_template="Research about {topic}",
result_key="research_result"
)
task2 = Task(
name="write_article",
agent=agent2,
prompt_template="Write an article using this research: {research_result}",
dependencies=[TaskDependency("research_topic", "research_result")]
)
# Assemble and launch your crew! 🚀
crew = Crew(
agents={"research": agent1, "writer": agent2},
tasks=[task1, task2],
initial_context={"topic": "AI agents"}
)
results = crew.execute()
🔧 Advanced Usage
Task Execution Evaluation
SmolagentsCrew includes a evaluation system that helps you track and analyze task execution performance. You can enable evaluation to:
- Monitor task execution times
- Track parallel execution patterns
- Analyze task dependencies
- Generate detailed execution reports
Here's how to use the evaluation feature:
# Enable evaluation when executing the crew
results = crew.execute(evaluate=True)
# The execution report will be automatically printed, showing:
# - Total execution time
# - Individual task execution times
# - Agent assignments
# - Task dependencies
# - Parallel execution groups
Example output:
Crew Execution Report
--------------------
Total Execution Time: 15.42 seconds
Task Execution Details:
Task: research_topic
Agent: researcher
Execution Time: 8.31 seconds
Task: write_article
Agent: writer
Execution Time: 7.11 seconds
Dependencies: research_topic
Parallel Execution Groups:
research_topic ran in parallel with: write_article
Using the Builder Pattern
SmolagentsCrew provides a builder pattern that simplifies the process of creating and configuring complex agent workflows. The builder pattern allows you to:
- Construct crews step by step with clear, readable code
- Validate agent configurations and dependencies automatically
- Create reusable agent templates and workflows
- Handle complex task chains and dependencies with ease
Here's how to use our builder pattern:
import os
os.environ["OPENAI_API_KEY"] = "sk-..."
from smolagents_crew import CrewBuilder, Task, Agent
from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool
# Create a builder instance
builder = CrewBuilder()
# Create and add research agent
research_agent = Agent(
"researcher",
agent_instance=CodeAgent,
model=OpenAIServerModel('gpt-4'),
tools=[DuckDuckGoSearchTool()]
)
builder.add_agent("researcher", research_agent)
# Create and add writer agent
writer_agent = Agent(
"writer",
agent_instance=CodeAgent,
model=OpenAIServerModel('gpt-4'),
tools=[]
)
builder.add_agent("writer", writer_agent)
# Create research task
research_task = Task(
name="research_topic",
agent=research_agent,
prompt_template="Research about {topic} and provide key findings",
result_key="research_findings"
)
# Create writing task that depends on research results
writing_task = Task(
name="write_article",
agent=writer_agent,
prompt_template="Write an article using the following research: {research_findings}",
result_key="final_article",
dependencies=[TaskDependency("research_topic", "research_findings")]
)
# Add tasks to the builder
builder.add_task(research_task)
builder.add_task(writing_task)
# Add shared context
builder.add_shared_context("topic", "Artificial Intelligence in Healthcare")
# Print the crew structure for visualization
builder.print_crew()
# Build and execute the crew
crew = builder.build()
results = crew.execute()
# Access the final article
print("\nFinal Article:")
print(results["final_article"])
Advanced Crew Building
SmolagentsCrew provides a builder pattern for creating complex agent crews. The CrewBuilder class offers advanced features for orchestrating sophisticated multi-agent workflows:
from smolagents_crew import CrewBuilder
# Create a crew using the builder pattern
builder = CrewBuilder()
# Add agents
builder.add_agent("researcher", researcher_agent)
.add_agent("writer", writer_agent)
.add_agent("editor", editor_agent)
# Create a chain of dependent tasks
builder.add_task_chain([
research_task, # First task
writing_task, # Automatically depends on research_task
editing_task # Automatically depends on writing_task
])
# Add shared context
builder.add_shared_context("topic", "AI Agents")
# Validate the crew configuration
builder.validate_crew()
# Print the crew structure
builder.print_crew()
# Build and execute
crew = builder.build()
results = crew.execute(evaluate=True)
Key features of advanced crew building:
- 🔗 Task Chaining: Automatically create linear task dependencies
- ✅ Crew Validation: Detect issues like circular dependencies or missing components
- 🎯 Shared Context: Easily manage data shared between tasks
- 📊 Visual Structure: Print a clear overview of your crew's configuration
- 🔄 Fluent Interface: Chain method calls for cleaner code
🤝 Contributing
Join our crew! We love contributions that make our framework even better. Feel free to submit a Pull Request! 💪
📄 License
This project is licensed under the MIT License - see the LICENSE file for details. 📜
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 smolagents_crew-0.1.1.tar.gz.
File metadata
- Download URL: smolagents_crew-0.1.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81ea6e389b66a28275e7cd239e3b082b90c46c8c7c1c8bb9a7983d18add4e6dd
|
|
| MD5 |
de1b8de4db0c736ecb023683d048ef68
|
|
| BLAKE2b-256 |
aeaea51faee741a6a21bfabbc9ccf5d9b7f1b3846fe76af8784c573c68906bef
|
File details
Details for the file smolagents_crew-0.1.1-py3-none-any.whl.
File metadata
- Download URL: smolagents_crew-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d6a1de0fa3eee8a32f6c0c157224c92bc4000646991e7a9f128d9f1212d2ea
|
|
| MD5 |
6ad56f2e62156ccd038a19d2e827cd25
|
|
| BLAKE2b-256 |
19c6f30b55f9546fc2a93b439f7c0c5b8a707d8ee1b04e35187c59c562c7e566
|