Skip to main content

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

Project description

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=10         # 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=10         # 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.

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

orch_lib-3.1.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

orch_lib-3.1.1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file orch_lib-3.1.1.tar.gz.

File metadata

  • Download URL: orch_lib-3.1.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for orch_lib-3.1.1.tar.gz
Algorithm Hash digest
SHA256 e0f96b00098878ee8eb3b93fc7078009a9d96024dc1ff24296f2f9101a3acdb7
MD5 0a026919a8d56de33516ad59a16e104e
BLAKE2b-256 05eca34f1275783136b9ca2e8347b55642b8468beed06cb584ad9bc780a41a74

See more details on using hashes here.

File details

Details for the file orch_lib-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: orch_lib-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for orch_lib-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7f8a49cef16eb404e6d822a1213ed79dec9a49fc8067f85a0b41550d24c3771
MD5 68890b0f00606c2df7b71cf25d5e78f5
BLAKE2b-256 7d256fe19dbfb52cc4b57d89728d8ea047f3afa2971dbf12343ee4ed20b0e198

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