Skip to main content

A lightweight framework for multi-agent orchestration, forked from OpenAI's Swarm library.

Project description

Troop

A lightweight framework for multi-agent orchestration, forked from OpenAI's Swarm library.

Install

Requires Python 3.10+

pip install git+https://github.com/pietz/troop.git

Usage

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:

  1. Agent: Encapsulates instructions and tools
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

troop-0.0.5.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

troop-0.0.5-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file troop-0.0.5.tar.gz.

File metadata

  • Download URL: troop-0.0.5.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for troop-0.0.5.tar.gz
Algorithm Hash digest
SHA256 25237e5e7af520d2f02617bc4bfdfcd1de65d069007c443d7d143f06967aab5f
MD5 26f1f5267f4f75a84603699d55e2ba4b
BLAKE2b-256 d99a9ad3aae84de226c7eae92d139b3f0d7618f5a6aca1190a6e0b0cdbbdd3e8

See more details on using hashes here.

File details

Details for the file troop-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: troop-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for troop-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 08aed2413ee94c7534e5c33e0a2560940dadfceaad16b882e57656087ba020bc
MD5 bef1feb2e4c8ebbb9fe14a1733dc5bf5
BLAKE2b-256 f707877c54ee2c1281e507d9f02341c9dc55a7f31dd82497a36a4e7495f2d59e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page