A lightweight framework for multi-agent orchestration, forked from OpenAI's Swarm library.
Project description
Troop
A simple and lightweight framework for multi-agent orchestration, forked from OpenAI's Swarm library.
There are many great and powerful LLM agent libraries out there. troop is trying to become a simple, flexible and production-ready alternative that let's you focus on your projects instead of spending time on learning complex tools.
OpenAI and Anthropic have both shared their thoughts on what
Install
Requires Python 3.10+
pip install git+https://github.com/pietz/troop.git
Usage
Currently, troop is a drop-in replacement for swarm from OpenAI. Change the imports and your existing code should work. While I want to try to keep it this way, future features might introduce breaking changes.
from troop import Troop, Agent
client = Troop()
def transfer_to_agent_b():
return agent_b
agent_a = Agent(
name="Agent A",
instructions="You are a helpful agent.",
functions=[transfer_to_agent_b],
)
agent_b = Agent(
name="Agent B",
instructions="Only speak in Haikus.",
)
response = client.run(
agent=agent_a,
messages=[{"role": "user", "content": "I want to talk to agent B."}],
)
print(response.messages[-1]["content"])
Overview
Troop focuses on lightweight agent coordination and execution through two core abstractions:
Agent: Encapsulates instructions and tools- Handoffs: Allows agents to transfer control to other agents
These primitives enable building scalable multi-agent systems while maintaining simplicity.
Documentation
Running Troop
Initialize a client:
from troop import Troop
client = Troop()
Client.run() Arguments
| Argument | Type | Description | Default |
|---|---|---|---|
| agent | Agent |
Initial agent to be called | (required) |
| messages | List |
List of message objects | (required) |
| context_variables | dict |
Additional context variables | {} |
| max_turns | int |
Maximum conversation turns | float("inf") |
| model_override | str |
Override agent's model | None |
| execute_tools | bool |
Execute tool calls | True |
| stream | bool |
Enable streaming responses | False |
| debug | bool |
Enable debug logging | False |
Agent Configuration
| Field | Type | Description | Default |
|---|---|---|---|
| name | str |
Agent name | "Agent" |
| model | str |
Model to use | "gpt-4" |
| instructions | str/func |
Agent instructions | "You are a helpful agent." |
| functions | List |
Available functions | [] |
| tool_choice | str |
Tool choice override | None |
Functions
Functions can:
- Return strings (or values castable to strings)
- Return other agents for handoffs
- Access context variables
- Update context through Result objects
Example with context variables:
def greet(context_variables, language):
user_name = context_variables["user_name"]
greeting = "Hola" if language.lower() == "spanish" else "Hello"
return f"{greeting}, {user_name}!"
agent = Agent(functions=[greet])
Streaming
stream = client.run(agent, messages, stream=True)
for chunk in stream:
print(chunk)
Testing
Use the built-in REPL for testing:
from troop.repl import run_demo_loop
run_demo_loop(agent, stream=True)
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 troop-0.0.9.tar.gz.
File metadata
- Download URL: troop-0.0.9.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d0743645a421bdb42e0cf8be72267d4f7311b536cd1f23cb4109253e8eff5eb
|
|
| MD5 |
a932ba8fc7a5754681a3e8e5ea71c07f
|
|
| BLAKE2b-256 |
56171a08157017e95272cdd946d447b3f28a1733162b191025ba34a9d8c5a153
|
File details
Details for the file troop-0.0.9-py3-none-any.whl.
File metadata
- Download URL: troop-0.0.9-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93e20c760f583425d370330637ab9e17347aaf6e948669d72093be5738f4745a
|
|
| MD5 |
bfcec98b3038a33c2af0b5bc5b2df2ca
|
|
| BLAKE2b-256 |
37dc4836321e8b20fcdc5fb8dddf3a2facc3af2eb00fde931e48ef6b632671e4
|