Coordinate AI agents in a workflow
Project description
SwarmCore
Coordinate AI agents in a workflow. pip install swarmcore.
Install
pip install swarmcore
Quickstart
import asyncio
from swarmcore import Agent, Swarm
researcher = Agent(
name="researcher",
instructions="Find key information about the given topic. Write detailed notes.",
model="anthropic/claude-opus-4-6",
)
writer = Agent(
name="writer",
instructions="Using the research notes in context, write a clear summary report.",
model="anthropic/claude-opus-4-6",
)
swarm = Swarm(
agents=[researcher, writer],
flow="researcher >> writer",
)
result = asyncio.run(swarm.run("What are the key trends in AI agents in 2025?"))
print(result.output)
The researcher runs first. Its output is stored in shared context. The writer runs next and sees the research notes in its prompt. result.output is the writer's final response.
Parallel Flows
Fan out to multiple agents, then fan back in:
swarm = Swarm(
agents=[planner, researcher, critic, writer],
flow="planner >> [researcher, critic] >> writer",
)
planner runs first. Then researcher and critic run in parallel (concurrent LLM calls). Then writer runs with all three outputs in context.
All parallel agents see the same context snapshot from before their step. They don't see each other's outputs during execution.
Tools
Give agents tools as plain Python functions:
def search_web(query: str) -> str:
"""Search the web for information."""
# your implementation
return results
agent = Agent(
name="researcher",
instructions="Use the search tool to find information.",
model="anthropic/claude-opus-4-6",
tools=[search_web],
)
Functions are automatically converted to OpenAI function-calling schemas using type hints and docstrings. The agent will call tools in a loop until it produces a final text response.
Async functions work too:
async def fetch_data(url: str) -> str:
"""Fetch data from a URL."""
...
Models
SwarmCore uses LiteLLM under the hood. Any LiteLLM-compatible model string works:
Agent(name="a", instructions="...", model="anthropic/claude-opus-4-6")
Agent(name="b", instructions="...", model="openai/gpt-4o")
Agent(name="c", instructions="...", model="ollama/llama3")
Agent(name="d", instructions="...", model="groq/llama-3.1-8b-instant")
Set the appropriate API key for your provider (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc).
API Reference
Agent(name, instructions, model, tools)
| Param | Type | Default | Description |
|---|---|---|---|
name |
str |
required | Unique identifier used in flow strings and context keys |
instructions |
str |
required | System prompt for this agent |
model |
str |
"anthropic/claude-opus-4-6" |
LiteLLM model string |
tools |
list[Callable] |
None |
Python functions for tool calling |
Swarm(agents, flow)
| Param | Type | Description |
|---|---|---|
agents |
list[Agent] |
All agents referenced in the flow |
flow |
str |
Execution flow: "a >> b" (sequential), "a >> [b, c] >> d" (parallel) |
SwarmResult
| Field | Type | Description |
|---|---|---|
output |
str |
Final agent's output |
context |
dict[str, str] |
All agent outputs keyed by agent name |
history |
list[AgentResult] |
Ordered execution results |
AgentResult
| Field | Type | Description |
|---|---|---|
agent_name |
str |
Agent that produced this result |
input_task |
str |
The task string passed to the agent |
output |
str |
Agent's text output |
model |
str |
Model used |
duration_seconds |
float |
Execution time |
token_usage |
TokenUsage |
Token counts (prompt, completion, total) |
Roadmap
- Conditional branching in flows
- Streaming responses
- Retry policies
- Agent memory / state persistence
- Dynamic re-planning
License
MIT
Project details
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 swarmcore-0.1.1.tar.gz.
File metadata
- Download URL: swarmcore-0.1.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68b8f71f701b28b3027fcd558218470e721b16d22bc7716e208cf09a2cd3b5f4
|
|
| MD5 |
cfa7fbb2d56e68ec11ba5217a4564b2c
|
|
| BLAKE2b-256 |
af1a53e8116e93a82ca146148909d57911692a8ac9283faaddcb535f342b6aaf
|
Provenance
The following attestation bundles were made for swarmcore-0.1.1.tar.gz:
Publisher:
python-publish.yml on MatchaOnMuffins/swarmcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
swarmcore-0.1.1.tar.gz -
Subject digest:
68b8f71f701b28b3027fcd558218470e721b16d22bc7716e208cf09a2cd3b5f4 - Sigstore transparency entry: 932968344
- Sigstore integration time:
-
Permalink:
MatchaOnMuffins/swarmcore@adf34f2c172268d7b7faa1661d034b87f413369b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/MatchaOnMuffins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@adf34f2c172268d7b7faa1661d034b87f413369b -
Trigger Event:
release
-
Statement type:
File details
Details for the file swarmcore-0.1.1-py3-none-any.whl.
File metadata
- Download URL: swarmcore-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e451230de5c7434b14aefc9249c46aed66ba4e4ab3896e2a1a8de7b5c918010
|
|
| MD5 |
86bb6785903fa26f3db8d7a7a7252851
|
|
| BLAKE2b-256 |
5249a3a8f08adee0dec4813049e8d99b226f69615184361fe8490b8cb6d3074b
|
Provenance
The following attestation bundles were made for swarmcore-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on MatchaOnMuffins/swarmcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
swarmcore-0.1.1-py3-none-any.whl -
Subject digest:
5e451230de5c7434b14aefc9249c46aed66ba4e4ab3896e2a1a8de7b5c918010 - Sigstore transparency entry: 932968379
- Sigstore integration time:
-
Permalink:
MatchaOnMuffins/swarmcore@adf34f2c172268d7b7faa1661d034b87f413369b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/MatchaOnMuffins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@adf34f2c172268d7b7faa1661d034b87f413369b -
Trigger Event:
release
-
Statement type: