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.5.0.tar.gz (32.0 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.5.0-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dapr_agents_oas_adapter-0.5.0.tar.gz
  • Upload date:
  • Size: 32.0 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.5.0.tar.gz
Algorithm Hash digest
SHA256 613394786d2544ee82f1467aadb3cf3d431030e99526b5d5d09929f68b6fac7c
MD5 31c74b1e12e1094ec36a8117559ea85f
BLAKE2b-256 7fec23562b43812083b25af34cb2b194a8740fd6170f4587cff5cc0a895054bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for dapr_agents_oas_adapter-0.5.0.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.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dapr_agents_oas_adapter-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddd0d7fd77b3047fe1f445d9058af496b898ee90be80d8d7de239ff61e18d512
MD5 3ad02564e7537e4d2a6a572a4f09ed1c
BLAKE2b-256 be4c3bb513e95c5dea3786201032d3ffdb560a23ea6aa2d02b4783e329635ce2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dapr_agents_oas_adapter-0.5.0-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