Skip to main content

Python SDK for building workflow automation agents with Erdo

Project description

Erdo Agent SDK

Build AI agents and workflows with Python. The Erdo Agent SDK provides a declarative way to create agents that can be executed by the Erdo platform.

Installation

pip install erdo

Quick Start

Creating Agents

Create agents using the Agent class and define steps with actions:

from erdo import Agent, state
from erdo.actions import memory, llm
from erdo.conditions import IsSuccess, GreaterThan

# Create an agent
data_analyzer = Agent(
    name="data analyzer",
    description="Analyzes data files and provides insights",
    running_message="Analyzing data...",
    finished_message="Analysis complete",
)

# Step 1: Search for relevant context
search_step = data_analyzer.step(
    memory.search(
        query=state.query,
        organization_scope="specific",
        limit=5,
        max_distance=0.8
    )
)

# Step 2: Analyze the data with AI
analyze_step = data_analyzer.step(
    llm.message(
        model="claude-sonnet-4-20250514",
        system_prompt="You are a data analyst. Analyze the data and provide insights.",
        query=state.query,
        context=search_step.output.memories,
        response_format={
            "Type": "json_schema",
            "Schema": {
                "type": "object",
                "required": ["insights", "confidence", "recommendations"],
                "properties": {
                    "insights": {"type": "string", "description": "Key insights found"},
                    "confidence": {"type": "number", "description": "Confidence 0-1"},
                    "recommendations": {"type": "array", "items": {"type": "string"}},
                },
            },
        },
    ),
    depends_on=search_step,
)

Code Execution with External Files

Use the @agent.exec decorator to execute code with external Python files:

from erdo.types import PythonFile

@data_analyzer.exec(
    code_files=[
        PythonFile(filename="analysis_files/analyze.py"),
        PythonFile(filename="analysis_files/utils.py"),
    ]
)
def execute_analysis():
    """Execute detailed analysis using external code files."""
    from analysis_files.analyze import analyze_data
    from analysis_files.utils import prepare_data

    # Prepare and analyze data
    prepared_data = prepare_data(context.parameters.get("dataset", {}))
    results = analyze_data(context)

    return results

Conditional Step Execution

Handle step results with conditions:

from erdo.conditions import IsSuccess, GreaterThan

# Store high-confidence results
analyze_step.on(
    IsSuccess() & GreaterThan("confidence", "0.8"),
    memory.store(
        memory={
            "content": analyze_step.output.insights,
            "description": "High-confidence data analysis results",
            "type": "analysis",
            "tags": ["analysis", "high-confidence"],
        }
    ),
)

# Execute detailed analysis for high-confidence results
analyze_step.on(
    IsSuccess() & GreaterThan("confidence", "0.8"),
    execute_analysis
)

Complex Execution Modes

Use execution modes for advanced workflows:

from erdo import ExecutionMode, ExecutionModeType
from erdo.actions import bot
from erdo.conditions import And, IsAny
from erdo.template import TemplateString

# Iterate over resources
analyze_files = agent.step(
    action=bot.invoke(
        bot_name="file analyzer",
        parameters={"resource": TemplateString("{{resources}}")},
    ),
    key="analyze_files",
    execution_mode=ExecutionMode(
        mode=ExecutionModeType.ITERATE_OVER,
        data="parameters.resource",
        if_condition=And(
            IsAny(key="dataset.analysis_summary", value=["", None]),
            IsAny(key="dataset.type", value=["FILE"]),
        ),
    )
)

Loading Prompts

Use the Prompt class to load prompts from files:

from erdo import Prompt

# Load prompts from a directory
prompts = Prompt.load_from_directory("prompts")

# Use in your agent steps
step = agent.step(
    llm.message(
        system_prompt=prompts.system_prompt,
        query=state.query,
    )
)

State and Templating

Access dynamic data using the state object and template strings:

from erdo import state
from erdo.template import TemplateString

# Access input parameters
query = state.query
dataset = state.dataset

# Use in template strings
template = TemplateString("Analyzing: {{query}} for dataset {{dataset.id}}")

Core Concepts

Actions

Actions are the building blocks of your agents. Available action modules:

  • erdo.actions.memory - Memory storage and search
  • erdo.actions.llm - Large language model interactions
  • erdo.actions.bot - Bot invocation and orchestration
  • erdo.actions.codeexec - Code execution
  • erdo.actions.utils - Utility functions
  • erdo.actions.resource_definitions - Resource management

Conditions

Conditions control when steps execute:

  • IsSuccess(), IsError() - Check step status
  • GreaterThan(), LessThan() - Numeric comparisons
  • TextEquals(), TextContains() - Text matching
  • And(), Or(), Not() - Logical operators

Types

Key types for agent development:

  • Agent - Main agent class
  • ExecutionMode - Control step execution behavior
  • PythonFile - Reference external Python files
  • TemplateString - Dynamic string templates
  • Prompt - Prompt management

Advanced Features

Multi-Step Dependencies

Create complex workflows with step dependencies:

step1 = agent.step(memory.search(...))
step2 = agent.step(llm.message(...), depends_on=step1)
step3 = agent.step(utils.send_status(...), depends_on=[step1, step2])

Dynamic Data Access

Use the state object to access runtime data:

# Access nested data
user_id = state.user.id
dataset_config = state.dataset.config.type

# Use in actions
step = agent.step(
    memory.search(query=f"data for user {state.user.id}")
)

Error Handling

Handle errors with conditions and fallback steps:

from erdo.conditions import IsError

main_step = agent.step(llm.message(...))

# Handle errors
main_step.on(
    IsError(),
    utils.send_status(
        message="Analysis failed, please try again",
        status="error"
    )
)

CLI Integration

Deploy your agents using the Erdo CLI:

# Install the CLI
pip install erdo
erdo install-cli

# Login to your Erdo account
erdo login

# Sync your agents
erdo sync

Examples

See the examples/ directory for complete examples:

  • agent_centric_example.py - Comprehensive agent with multiple steps
  • state_example.py - State management and templating

API Reference

Core Classes

  • Agent: Main agent class for creating workflows
  • ExecutionMode: Control step execution (iterate, conditional, etc.)
  • Prompt: Load and manage prompt templates

Actions

  • memory: Store and search memories
  • llm: Interact with language models
  • bot: Invoke other bots and agents
  • codeexec: Execute Python code
  • utils: Utility functions (status, notifications, etc.)

Conditions

  • Comparison: GreaterThan, LessThan, TextEquals, etc.
  • Status: IsSuccess, IsError, IsNull, etc.
  • Logical: And, Or, Not

State & Templating

  • state: Access runtime parameters and data
  • TemplateString: Dynamic string templates with {{variable}} syntax

License

Commercial License - see LICENSE file for details.

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

erdo-0.1.4.tar.gz (50.5 kB view details)

Uploaded Source

Built Distribution

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

erdo-0.1.4-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file erdo-0.1.4.tar.gz.

File metadata

  • Download URL: erdo-0.1.4.tar.gz
  • Upload date:
  • Size: 50.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for erdo-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f44f764150ed00ce3d8a67c08a55695edb8a92511870480ff34f6ede1b7528b8
MD5 c91ef8cf8cf7ed0c8d0407c21f57853d
BLAKE2b-256 1e90b6675ca5a8f93e557df07ddf979c4c3ee46841cd6772fb420d92adaf8fec

See more details on using hashes here.

Provenance

The following attestation bundles were made for erdo-0.1.4.tar.gz:

Publisher: publish.yml on erdoai/erdo-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file erdo-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: erdo-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 53.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for erdo-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d2cebeff53cc5ed390cf2d8f4f91b1bc8e4abe1c3c20bec630f6fb3cacd5a054
MD5 4894a369b3908f0b05ce4e3cc1612f74
BLAKE2b-256 4d005113b52c27d0fd215c884d983b7dbd57ba18536e9793741936c457114d7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for erdo-0.1.4-py3-none-any.whl:

Publisher: publish.yml on erdoai/erdo-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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