Skip to main content

Adapter library to make Dapr Agents compatible with Open Agent Spec

Project description

Dapr Agents OAS Adapter

Adapter library enabling bidirectional interoperability between Open Agent Spec (OAS) and Dapr Agents.

Features

  • OAS → Dapr Agents Import: Loads OAS specifications (JSON/YAML) and creates executable Dapr Agents and workflows
  • Dapr Agents → OAS Export: Exports Dapr agents and workflows to OAS format
  • Component Converters: Support for Agent, Flow, LlmConfig, Tool, Node and Edge
  • Code Generation: Generates Python code for Dapr workflows from OAS specifications
  • Compatibility: Follows existing adapter patterns (LangGraph, CrewAI)

Installation

# Using uv (recommended)
uv add dapr-agents-oas-adapter

# Or using pip
pip install dapr-agents-oas-adapter

Quick Start

Load an OAS specification

from dapr_agents_oas_adapter import DaprAgentSpecLoader

# Register tool implementations
def search_tool(query: str) -> list[str]:
    """Web search."""
    return ["result1", "result2"]

loader = DaprAgentSpecLoader(
    tool_registry={"search": search_tool}
)

# Load from JSON
with open("agent_spec.json") as f:
    config = loader.load_json(f.read())

# Create executable Dapr agent
agent = loader.create_agent(config)

# Start the agent
await agent.start()

Export to OAS

from dapr_agents_oas_adapter import DaprAgentSpecExporter
from dapr_agents_oas_adapter.types import DaprAgentConfig

exporter = DaprAgentSpecExporter()

# Configure agent
config = DaprAgentConfig(
    name="my_assistant",
    role="Assistant",
    goal="Help users",
    instructions=["Be helpful", "Be concise"],
    tools=["search", "calculator"],
)

# Export to JSON
json_spec = exporter.to_json(config)

# Export to YAML file
exporter.to_yaml_file(config, "agent_spec.yaml")

Working with Workflows

from dapr_agents_oas_adapter import DaprAgentSpecLoader, DaprAgentSpecExporter
from dapr_agents_oas_adapter.types import (
    WorkflowDefinition,
    WorkflowTaskDefinition,
    WorkflowEdgeDefinition,
)

# Create workflow definition
workflow = WorkflowDefinition(
    name="my_workflow",
    description="Processes user data",
    tasks=[
        WorkflowTaskDefinition(name="start", task_type="start"),
        WorkflowTaskDefinition(
            name="analyze",
            task_type="llm",
            config={"prompt_template": "Analyze: {{input}}"},
        ),
        WorkflowTaskDefinition(name="end", task_type="end"),
    ],
    edges=[
        WorkflowEdgeDefinition(from_node="start", to_node="analyze"),
        WorkflowEdgeDefinition(from_node="analyze", to_node="end"),
    ],
    start_node="start",
    end_nodes=["end"],
)

# Export to OAS
exporter = DaprAgentSpecExporter()
oas_spec = exporter.to_json(workflow)

# Generate workflow Python code
loader = DaprAgentSpecLoader()
code = loader.generate_workflow_code(workflow)
print(code)

Component Mapping

OAS Component Dapr Agents Equivalent
Agent AssistantAgent / ReActAgent
Flow @workflow decorated function
LlmNode @task with LLM call
ToolNode @task with tool call
StartNode Workflow entry point
EndNode Workflow return
ServerTool @tool decorated function
MCPTool MCP integration via Dapr
LlmConfig DaprChatClient config
ControlFlowEdge Sequence of yield ctx.call_activity()
DataFlowEdge Parameter passing between tasks

API Reference

DaprAgentSpecLoader

class DaprAgentSpecLoader:
    def __init__(self, tool_registry: dict[str, Callable] | None = None)
    def load_json(self, json_content: str) -> DaprAgentConfig | WorkflowDefinition
    def load_yaml(self, yaml_content: str) -> DaprAgentConfig | WorkflowDefinition
    def load_json_file(self, file_path: str | Path) -> DaprAgentConfig | WorkflowDefinition
    def load_yaml_file(self, file_path: str | Path) -> DaprAgentConfig | WorkflowDefinition
    def load_component(self, component: Component) -> DaprAgentConfig | WorkflowDefinition
    def load_dict(self, spec_dict: dict) -> DaprAgentConfig | WorkflowDefinition
    def create_agent(self, config: DaprAgentConfig, additional_tools: dict | None = None) -> Any
    def create_workflow(self, workflow_def: WorkflowDefinition, task_implementations: dict | None = None) -> Callable
    def generate_workflow_code(self, workflow_def: WorkflowDefinition) -> str
    def register_tool(self, name: str, implementation: Callable) -> None

DaprAgentSpecExporter

class DaprAgentSpecExporter:
    def to_json(self, component: DaprAgentConfig | WorkflowDefinition, indent: int = 2) -> str
    def to_yaml(self, component: DaprAgentConfig | WorkflowDefinition) -> str
    def to_dict(self, component: DaprAgentConfig | WorkflowDefinition) -> dict
    def to_component(self, component: DaprAgentConfig | WorkflowDefinition) -> Component
    def to_json_file(self, component: DaprAgentConfig | WorkflowDefinition, file_path: str | Path) -> None
    def to_yaml_file(self, component: DaprAgentConfig | WorkflowDefinition, file_path: str | Path) -> None
    def from_dapr_agent(self, agent: Any) -> DaprAgentConfig
    def from_dapr_workflow(self, workflow_func: Callable, task_funcs: list[Callable] | None = None) -> WorkflowDefinition
    def export_agent_to_json(self, agent: Any) -> str
    def export_agent_to_yaml(self, agent: Any) -> str

Development

Setup

git clone https://github.com/heltondoria/dapr-agents-oas-adapter.git
cd dapr-agents-oas-adapter
uv sync --all-groups

Run Tests

uv run pytest

Linting and Type Checking

uv run ruff check src/
uv run mypy src/

Requirements

  • Python >= 3.12
  • pyagentspec >= 25.4.1
  • dapr-agents >= 0.10.4
  • dapr >= 1.16.0
  • pydantic >= 2.0.0

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Links

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

dapr_agents_oas_adapter-0.4.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

dapr_agents_oas_adapter-0.4.1-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file dapr_agents_oas_adapter-0.4.1.tar.gz.

File metadata

  • Download URL: dapr_agents_oas_adapter-0.4.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dapr_agents_oas_adapter-0.4.1.tar.gz
Algorithm Hash digest
SHA256 67c395c207ed93bdc607a85ae31ed7ae52292ff3007dcee04774e4623011d0a8
MD5 bfc40e586172e3014702129d3fc0a0ec
BLAKE2b-256 8728ff05864148675bd45a1f1003878948bd0864e966933d258ba90e671d8eb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dapr_agents_oas_adapter-0.4.1.tar.gz:

Publisher: publish.yml on heltondoria/dapr-agents-oas-adapter

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

File details

Details for the file dapr_agents_oas_adapter-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dapr_agents_oas_adapter-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e2a1c0895208d4b0ee9760ed2011c61cf3d36420538fbad4b887d22f204bc06
MD5 e4cdec66ddaa97ec82074e4cc4405980
BLAKE2b-256 b84c69d2a1f368acddda94dde6f2117f2a88c64b7ebac13fef53a696120c9551

See more details on using hashes here.

Provenance

The following attestation bundles were made for dapr_agents_oas_adapter-0.4.1-py3-none-any.whl:

Publisher: publish.yml on heltondoria/dapr-agents-oas-adapter

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