Skip to main content

orch-lib

A Python library for agent orchestration with task scheduling, conditional routing, and memory management.

Features

  • Agent Orchestration: Build complex multi-agent workflows with central coordination
  • Task Management: Define and execute tasks with memory scoping
  • Conditional Routing: Route task execution based on dynamic conditions
  • Memory Management: Isolated and shared memory across agents and graphs
  • Graph Execution: Coordinate multiple agents at the graph level
  • Expression Evaluation: Evaluate dynamic expressions with memory access

Installation

pip install orch-lib

Quick Start

Basic Agent Example

from orch_lib import Agent, Task, Memory

# Create an agent
agent = Agent(name="worker")

# Define a task
def process_data(scope=None):
    scope["private"]["result"] = "processed"
    return scope["private"]["result"]

task = Task("process", process_data)

# Add task to agent
agent.add_task("process", task)
agent.add_route("process", "on_start")

# Execute agent
agent()

Agent with Conditional Routing

from orch_lib import Agent, Task, Conditional, Memory

agent = Agent(memory=Memory())
agent.memory.store("should_run", True)

def task_fn(*args, scope=None):
    print("Task executed!")

agent.add_task("work", Task("work", task_fn))
agent.add_route("work", Conditional("private['should_run']"))

agent(max_passes=2)

Graph-Level Orchestration

from orch_lib import Graph, Agent, Task, Conditional

graph = Graph()

# Create agents
agent1 = Agent()
agent2 = Agent(parent=graph)

# Configure agents with tasks and routes
# ... (add tasks and routes as shown above)

# Add to graph
graph.add_agent("agent1", agent1)
graph.add_agent("agent2", agent2)

# Execute graph
graph()

Core Concepts

Memory

Agents and graphs maintain isolated memory spaces:

  • Private Memory: Agent-level memory not accessible to other agents
  • Public Memory: Graph-level memory accessible to all agents
  • Agent Memory: Per-agent memory in graph context

Tasks

Tasks are callable units of work:

task = Task(
    name="my_task",
    function=my_function,
    memories={"key": "value"}  # task-level memory
)

Conditionals

Routes can be conditional:

condition = Conditional("private['flag'] and public['enabled']")
agent.add_route("task_id", condition)

Expressions

Evaluate expressions with memory context:

from orch_lib import Expression

expr = Expression("count + 1")
result = expr(parent={"count": 5})

API Reference

Agent

Agent(
    tasks=None,           # dict of Task objects
    memory=None,          # Memory object
    routes=None,          # dict of routes
    name=None,            # agent name
    parent=None,          # parent memory reference
    max_passes=10000      # max execution passes
)

Task

Task(
    name: str,
    function: Callable,
    memories: dict = None
)

Conditional

Conditional(
    condition: str,       # Python expression string
    parent=None           # parent memory reference
)

Memory

Memory(agents=None)

Methods: store(), retrieve(), delete(), clear(), clear_agent_memory()

Graph

Graph(
    agents=None,          # dict of Agent objects
    memory=None,          # Memory object
    routes=None,          # dict of conditional routes
    max_passes=10000      # max execution passes
)

Development

Setup

pip install -e ".[dev]"

Running Tests

pytest

Code Quality

black src/
ruff check src/
mypy src/

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Metadata

Release files for orch-lib 3.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for orch-lib 3.3.1
File Size Uploaded Provenance Actions
orch_lib-3.3.1.tar.gz 21.5 kB Without provenance Details for orch_lib-3.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for orch-lib 3.3.1
File Interpreter ABI Platform Actions
orch_lib-3.3.1-py3-none-any.whl Python 3 none any Details for orch_lib-3.3.1-py3-none-any.whl

Total release size: 45.0 kB

Release files / orch_lib-3.3.1.tar.gz

Download URL orch_lib-3.3.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e835ddbd27e97018f0ff2686372716aa7054274e84d2d72304467371ac2bd958
BLAKE2b-256 checksum
How to use checksums
1a1c4148995e9cbea11a2f9a2eb4e87acbcb22f835b1f8c90a206d6a647e8094
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / orch_lib-3.3.1-py3-none-any.whl

Download URL orch_lib-3.3.1-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88f366df73805ba1ecdd0dd180c5d79985af1a2f9f1e11333a8b1060d136c874
BLAKE2b-256 checksum
How to use checksums
ec45f50c6ca17275e1b46c705ab700ec3cfdd58ae9c0578b3e92d98cc6faeac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for orch-lib 3.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page