Skip to main content

SDK for building orchagent agents - enables agent-to-agent calls with local execution support

Project description

orchagent SDK

Official Python SDK for building orchagent agents with agent-to-agent call support.

Installation

pip install orchagent-sdk

Note: The pip package is orchagent-sdk but the Python import is from orchagent import .... This is a common Python convention (e.g. Pillowimport PIL).

Quick Start

# pip install orchagent-sdk  (package name)
from orchagent import AgentClient  # module name

# Create a client (uses ORCHAGENT_SERVICE_KEY env var)
client = AgentClient()

# Call another agent
async def my_orchestrator(input_data):
    result = await client.call("joe/leak-finder@v1", {"url": input_data["repo"]})
    return result

Features

  • Agent-to-agent calls - Call other agents from within your orchestrator agent
  • Service key authentication - Automatic auth via ORCHAGENT_SERVICE_KEY env var
  • Call chain tracking - Prevents circular dependencies (A calls B calls A)
  • Deadline propagation - Timeout context flows through the call chain
  • Local execution mode - Test orchestrators locally with orch run --with-deps

Usage

Basic Usage

from orchagent import AgentClient

client = AgentClient()
result = await client.call("org/agent@v1", {"input": "data"})
# result is the raw agent output — the gateway envelope is auto-unwrapped

With FastAPI

Extract call context from incoming requests:

from fastapi import Request
from orchagent import AgentClient

@app.post("/analyze")
async def analyze(request: Request, input: AnalyzeInput):
    # Automatically extracts call chain, deadline, etc. from request headers
    client = AgentClient.from_request(request)
    secrets = await client.call("joe/leak-finder@v1", {"url": input.repo_url})
    return {"secrets": secrets}

Error Handling

from orchagent import (
    AgentClient,
    DependencyCallError,
    CallChainCycleError,
    TimeoutExceededError,
)

try:
    result = await client.call("org/agent@v1", data)
except CallChainCycleError:
    # Would create a circular dependency
    pass
except TimeoutExceededError:
    # Deadline passed
    pass
except DependencyCallError as e:
    # Agent returned an error
    print(f"Status: {e.status_code}, Body: {e.response_body}")

Local Execution Mode

When running with orch run --with-deps, the SDK automatically detects local mode and spawns sub-agents as local subprocesses instead of making HTTP calls.

# Agents are executed locally as subprocesses
orch run orchagent/security-review --with-deps --input '{"path": "."}'

This is controlled by the ORCHAGENT_LOCAL_EXECUTION=true environment variable, which the CLI sets automatically.

Environment Variables

Variable Description
ORCHAGENT_SERVICE_KEY Service key for API authentication. Auto-injected by the gateway for agents with manifest dependencies — do not add to required_secrets
ORCHAGENT_GATEWAY_URL Gateway URL (default: https://api.orchagent.io)
ORCHAGENT_LOCAL_EXECUTION Enable local subprocess execution
ORCHAGENT_AGENTS_DIR Path to local agents (default: ~/.orchagent/agents)

API Reference

AgentClient

class AgentClient:
    def __init__(
        self,
        service_key: str | None = None,      # From ORCHAGENT_SERVICE_KEY
        gateway_url: str | None = None,       # From ORCHAGENT_GATEWAY_URL
        call_chain: list[str] | None = None,  # Current call chain
        deadline_ms: int | None = None,       # Deadline timestamp
        max_hops: int | None = None,          # Max remaining hops
    ): ...

    @classmethod
    def from_request(cls, request, service_key=None) -> "AgentClient": ...

    async def call(
        self,
        agent_ref: str,           # "org/agent@version"
        input_data: dict,         # Input payload
        endpoint: str | None,     # Optional endpoint override
        timeout: float | None,    # Optional timeout in seconds
    ) -> Any: ...
    # Returns the raw agent output, not the gateway envelope.
    # The gateway wraps responses in {"data": ..., "metadata": ...} —
    # the SDK auto-unwraps this so you get the agent's output directly.

Exceptions

  • AgentClientError - Base exception
  • DependencyCallError - Agent call failed (has status_code, response_body)
  • CallChainCycleError - Would create circular dependency
  • TimeoutExceededError - Deadline passed
  • LocalExecutionError - Subprocess execution failed (has exit_code, stderr)

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

orchagent_sdk-0.1.11.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

orchagent_sdk-0.1.11-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file orchagent_sdk-0.1.11.tar.gz.

File metadata

  • Download URL: orchagent_sdk-0.1.11.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for orchagent_sdk-0.1.11.tar.gz
Algorithm Hash digest
SHA256 7cdd1c8d8ffb7d457dcc7b955280db5946977707f82bdcadd413a0b1b9f25f20
MD5 c0e68eb87e586866434cdca8c4a77a28
BLAKE2b-256 4d96ccce45fca2a6ae2bec50fa05d7e3c222211a254ff353ecfd2093ae89f396

See more details on using hashes here.

File details

Details for the file orchagent_sdk-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: orchagent_sdk-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for orchagent_sdk-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a9a62b4d2e04b92a1699105d7be38a825c0ee7ebd02dad7cf088b0886db4c48d
MD5 4d464483f5c873964a8778d77e1eedfd
BLAKE2b-256 57ec2dc4e8a234ae4e4a9a9fe2d14a86a2d49ccf654d98e3508da5b11d8152db

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