Agentspan Documentation

repository·main·Indexed 19 days ago

https://github.com/agentspan-ai/agentspan

A durable runtime for AI agents built on Conductor, providing long-running, event-driven, and dynamic (Plan-Execute) agent execution. It features automatic crash recovery, human-in-the-loop capabilities, and distributed worker support. The documentation covers the Agentspan CLI for server management and agent operation, agent configuration in YAML/JSON, and deployment options via Docker Compose, Helm charts, and Kubernetes manifests.

Tokens
368.7K
Snippets
1K
Records
1.4K
Agent score
61%

What's inside Agentspan

  1. Overview of Agentspan Python SDK

    main

    Agentspan is a distributed, durable runtime for AI agents designed to survive process crashes, scale across machines, and support long-running human-in-the-loop interactions.

    Unlike traditional frameworks that run agents in-memory, Agentspan compiles your agent definitions into server-side executions. This allows agents to continue running even if your local process is killed or your machine restarts. It is framework-agnostic: you can use existing agents from LangGraph, OpenAI Agents SDK, or Google ADK and wrap them in the Agentspan runtime to gain durability, crash recovery, and cross-process control via an execution ID.

    from conductor.ai.agents import Agent, AgentRuntime, tool
    
    @tool
    def get_weather(city: str) -> str:
        """Get current weather for a city."""
        return f"72F and sunny in {city}"
    
    agent = Agent(name="weatherbot", model="openai/gpt-4o", tools=[get_weather])
    
    with AgentRuntime() as runtime:
        result = runtime.run(agent, "What's the weather in NYC?")
        result.print_result()
  2. Overview of Agentspan Java SDK capabilities

    main

    The Agentspan Java SDK is designed for building long-running, dynamic, and event-driven AI agents. Unlike traditional thread-based SDKs, Agentspan leverages a durable runtime (built on Conductor) to provide:

    • Crash Resilience: Agents survive process crashes because state is managed by the Conductor workflow.
    • Distributed Tool Workers: Tool execution can be handled as distributed tasks rather than being limited to in-process execution.
    • Long-running Execution: Agents can run for days or weeks.
    • Native Human-in-the-loop: Supports native approval flows instead of polling hacks.
    • Full Observability: Provides a full workflow audit log for all agent activities.
  3. Agentspan Project Structure Overview

    main

    Understanding the repository layout helps in locating specific SDKs, examples, or deployment configurations:

    • cli/: Go-based CLI for server management.
    • server/: Java runtime server (Spring Boot + Conductor).
    • deployment/: Kubernetes manifests, Helm charts, and Docker Compose files.
    • ui/: React-based execution UI (accessible at localhost:6767).
    • sdk/python/: Python SDK, including 70+ progressive examples and validation frameworks.
    • sdk/typescript/: TypeScript SDK.
    • docs/: Consolidated documentation for SDK design, Python SDK, and the server.
  4. Use the Agentspan C# SDK Package Layout

    main

    The SDK is organized into several functional areas within the Conductor.AI namespace:

    • Core (Conductor.AI): Contains the Agent primitive, AgentBuilder, AgentRuntime (the primary entry point for orchestration), AgentClient (HTTP client), and Tool definitions.
    • Adapters: Thin wrappers that produce Agent objects with specific framework tags:
      • Conductor.AI.OpenAI: For OpenAI Agents SDK shapes.
      • Conductor.AI.GoogleADK: For Google ADK shapes.
      • Conductor.AI.SemanticKernel: For Microsoft Semantic Kernel (wraps [KernelFunction] methods into tools).
    • Feature Modules: Includes Guardrail, Handoff, Termination, Gate, Callback, Skill, and various CodeExecutor implementations (Local, Docker, Jupyter, Serverless).
  5. Overview of Multi-Agent Coordination Strategies

    main

    In Agentspan, multi-agent systems are built using the Agent primitive. You coordinate multiple agents by setting the agents=[...] parameter and selecting a strategy.

    Available strategies include:

    • handoff (default): The orchestrator LLM decides which sub-agent handles the request.
    • sequential: Sub-agents run in a fixed order, where each agent's output is passed as input to the next.
    • parallel: All sub-agents run concurrently; results are aggregated into result.sub_results.
    • router: A dedicated agent or a Python function selects which sub-agent to run.
    • swarm: Handoffs occur based on specific conditions (e.g., text patterns).
    • round_robin: Agents take turns in a fixed rotation.
    • random: A random sub-agent is selected each turn.
    • manual: A human selects which agent speaks each turn.
  6. Overview of Multi-Agent Strategies in Agentspan

    main

    Agentspan uses the Agent primitive to compose complex workflows using different orchestration strategies. Choose a strategy based on your workflow's structure:

    StrategyDescriptionUse when
    SEQUENTIALAgents run one after another; output of each feeds the nextLinear pipelines (e.g., research → write → edit)
    PARALLELAll sub-agents run concurrently; results are synthesizedIndependent parallel tasks
    HANDOFFSub-agent is called as a tool; parent LLM decides when and whichDynamic routing by LLM
    ROUTERA dedicated router agent decides which sub-agent runsRule-based or LLM-based routing
    SWARMAny agent can transfer control to another based on triggersOpen-ended conversation routing
    ROUND_ROBINSub-agents take turns in a fixed cycleStructured multi-agent discussions
    RANDOMA randomly-selected sub-agent runs each turnVaried multi-agent discussions
    PLAN_EXECUTEA planner agent produces a structured plan; steps execute against itComplex multi-step tasks with dependencies
    MANUALNo automatic orchestration; you drive the loopCustom control flow
  7. What is a Skill in Agentspan

    main

    A Skill is a portable, self-contained agent capability represented as a directory. Instead of writing complex code to define an agent, you define its purpose, parameters, and workflow in a SKILL.md file. The Agentspan Java SDK then loads this directory as a fully-configured Agent object ready for execution.

    Skill directory layout

    A skill directory typically follows this structure:

    my-skill/
    ├── SKILL.md              # Required — contains name, description, and workflow
    ├── search-agent.md       # Optional — defines a sub-agent
    ├── writer-agent.md       # Optional — defines a sub-agent
    └── scripts/              # Optional — contains scripts the agent can execute
        └── process.py
    my-skill/
    ├── SKILL.md
    ├── search-agent.md
    ├── writer-agent.md
    └── scripts/
        └── process.py
  8. Overview of E2E Test Suites

    main

    The Agentspan E2E test suite is divided into several specialized suites that validate different aspects of the SDKs and the Conductor orchestrator. Key suites include:

    • Suite 1: Basic Validation: Validates tool, guardrail, credential, and sub-agent compilation via plan().
    • Suite 2: Tool Calling / Credential Lifecycle: Validates the full credential pipeline (missing → env vars → CLI add/update).
    • Suite 3: CLI Tools / Credential Isolation: Validates command execution with whitelisting and isolation.
    • Suite 4: MCP Tools: Validates Model Context Protocol tool discovery and execution.
    • Suite 5: HTTP Tools / External OpenAPI: Validates http_tool() and OpenAPI spec discovery.
    • Suite 6: PDF Tools: Validates Markdown to PDF generation via pdf_tool().
    • Suite 7: Media Tools: Validates image (DALL-E 3, Gemini Imagen 3) and audio (OpenAI TTS-1) generation.
    • Suite 8: Guardrails: Validates regex, custom function, and LLM guardrails at both compilation and runtime.
    • Suite 9: Agent Handoffs: Validates multi-agent strategies (sequential, parallel, handoff, router, swarm, pipe operator).
    • Suite 10: Code Execution: Validates local Python, local Bash, Docker Python, and Jupyter execution.
    • Suite 11: LangGraph: Validates LangGraph framework detection, serialization, and routing.
    • Suite 12: Termination & Gates: Validates loop termination (TextMention, MaxMessage) and pipeline gates (TextGate).
    • Suite 13: Callbacks: Validates tool and model lifecycle hooks (on_tool_start, on_tool_end, etc.).
  9. Multi-Agent Strategies: Handoff, Parallel, and Pipelines

    main

    Agentspan supports complex multi-agent workflows through different orchestration strategies:

    Handoff

    Route requests between specialized agents using the strategy="handoff" parameter. One agent acts as a router to other agents.

    support = Agent(
        name="support",
        instructions="Route customer requests to the right team.",
        agents=[billing, technical],
        strategy="handoff",
    )

    Parallel

    Run multiple agents simultaneously to analyze different aspects of a prompt using strategy="parallel".

    analysis = Agent(
        name="analysis",
        agents=[market, risk],
        strategy="parallel"
    )

    Pipeline Composition

    Chain agents together using the >> operator to create a sequential workflow.

    pipeline = researcher >> writer >> editor
  10. Manage credentials and secrets for tools

    main

    Agentspan allows you to securely pass credentials to tools. Secrets are resolved from the server's secret store at execution time and injected as environment variables for worker tools. For HTTP/MCP tools, you can use ${NAME} substitution in headers.

    Methods of injection:

    1. Worker Tools: Define credentials: ['SECRET_NAME'] in the tool options. The secret is injected into process.env during the tool call.
    2. Explicit Fetching: Use getCredential('SECRET_NAME') inside the tool logic.
    3. HTTP Tools: Use ${SECRET_NAME} in the headers configuration.
    4. Agent Level: Pass credentials: [...] to the Agent constructor to authorize the agent to use those secrets.
    5. Call Time: Pass credentials: [...] in runtime.run(agent, prompt, { credentials: [...] }).

    Strict Mode: Set credentialStrictMode: true (or AGENTSPAN_CREDENTIAL_STRICT_MODE=true) to ensure that missing secrets cause a hard error instead of falling back to environment variables.

    import { Agent, tool, httpTool, getCredential } from '@conductor-oss/conductor-agent-sdk';
    
    // A worker tool: the secret is injected into the worker's process.env for the call
    const dbLookup = tool(
      async (args: { query: string }) => {
        const key = process.env.DB_API_KEY ?? '';
        return { ok: key !== '' };
      },
      {
        name: 'db_lookup',
        description: 'Look up data.',
        inputSchema: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'] },
        credentials: ['DB_API_KEY'],
      },
    );
    
    // Or fetch a credential explicitly inside a tool
    const analytics = tool(
      async (args: { topic: string }) => {
        const key = await getCredential('ANALYTICS_KEY');
        return { topic: args.topic, ok: !!key };
      },
      {
        name: 'analytics',
        description: 'Query analytics.',
        inputSchema: {
          type: 'object',
          properties: { topic: { type: 'string' } },
        },
        credentials: ['ANALYTICS_KEY']
      },
    );
    
    // HTTP tool with ${CRED} header substitution
    const searchApi = httpTool({
      name: 'search_api',
      description: 'Search.',
      url: 'https://api.example.com/search',
      headers: { Authorization: 'Bearer ${SEARCH_API_KEY}' },
      credentials: ['SEARCH_API_KEY'],
    });
    
    const agent = new Agent({
      name: 'credentialed_agent',
      model: 'anthropic/claude-sonnet-4-6',
      instructions: '…',
      tools: [dbLookup, analytics, searchApi],
      credentials: ['DB_API_KEY', 'ANALYTICS_KEY', 'SEARCH_API_KEY'],
    });
  11. Observe Claude Agent SDK execution with hooks

    main

    Even though the Claude Agent SDK runs in a passthrough worker, it is not a black box. Agentspan uses a hook system to provide visibility into tool usage, subagent activity, and notifications.

    Hook Behavior:

    • Defensive: All hooks are wrapped in try/except blocks and return {} to ensure they do not interfere with agent execution.
    • Priority: User-provided hooks run before Agentspan's internal instrumentation hooks.
    • Delivery: Events are delivered via a fire-and-forget mechanism using a shared ThreadPoolExecutor.

    Hook Mapping

    Hook EventStream Event TypeMetadata Mutated
    PreToolUsetool_calltool_call_count, tools_used
    PostToolUsetool_result
    PostToolUseFailuretool_errortool_error_count
    SubagentStartsubagent_startsubagent_count
    SubagentStopsubagent_stop
    Notificationnotification
    Stopagent_stop
  12. Use Graph-Structure for custom StateGraphs

    main

    If you use a custom StateGraph with a detectable model but no ToolNode tools, Agentspan uses the Graph-Structure path. This maps LangGraph components to specific Conductor tasks:

    • Nodes:
      • Regular functions $\rightarrow$ SIMPLE worker.
      • LLM nodes $\rightarrow$ A three-task pipeline (prep $\rightarrow$ LLM_CHAT_COMPLETE $\rightarrow$ finish).
      • @human_task $\rightarrow$ Conductor HUMAN task.
    • Edges: (source, target) mapping.
    • Conditional Edges: (source, router_func, target_map) mapping to a router (SIMPLE) $\rightarrow$ SWITCH pattern.
    • State Reducers: Mapped from graph.channels (e.g., operator.add).
    • Retry Policies: Mapped from node metadata.
    • Recursion Limit: Mapped from graph.config.
    raw_config = {
        "name": "my_workflow",
        "model": "anthropic/claude-sonnet-4-6",
        "_graph": {
            "nodes": [
                {"name": "fetch", "_worker_ref": "my_workflow_fetch"},
                {"name": "analyze", "_llm_node": True,
                 "_llm_prep_ref": "my_workflow_analyze_prep",
                 "_llm_finish_ref": "my_workflow_analyze_finish"},
                {"name": "review", "_human_node": True, "_human_prompt": "Review the analysis"},
            ],
            "edges": [{"source": "fetch", "target": "analyze"}],
            "conditional_edges": [
                {"source": "review", "_router_ref": "my_workflow_review_router",
                 "targets": {"approve": "__end__", "revise": "analyze"}}
            ],
            "_reducers": {"results": "add"},
            "_retry_policies": {"fetch": {"max_attempts": 3}},
            "_recursion_limit": 25
        }
    }