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.6.0.tar.gz (32.4 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.6.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dapr_agents_oas_adapter-0.6.0.tar.gz
  • Upload date:
  • Size: 32.4 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.6.0.tar.gz
Algorithm Hash digest
SHA256 ceb7d3df958953e5a5687d910e14636703c7ab40525e4a3ff142d2d4f51ba139
MD5 cbc52063544dd70226d2ff3bb33b2df5
BLAKE2b-256 29545bcf495ab884c8c4f0e71fa2b8dd9ac17c6c34db05bd4db718084bdd3c3c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for dapr_agents_oas_adapter-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55c48374392edcd2f4234d8e4a5a37af3b68094f9f0f614092a451df8fd42909
MD5 d0b83d74f1c51ad20e6de616d2d0b3ae
BLAKE2b-256 9b2387a727946d2e39b322bb5361576ae1fffef8a37745d7f1c80b73af9bdcd5

See more details on using hashes here.

Provenance

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