Skip to main content

Python SDK for DuraGraph - Reliable AI Workflow Orchestration

Project description

DuraGraph Python SDK

PyPI version Python License

Python SDK for DuraGraph - Reliable AI Workflow Orchestration.

Build AI agents with decorators, deploy to a control plane, and get full observability out of the box.

Installation

pip install duragraph-python

# With OpenAI support
pip install duragraph-python[openai]

# With Anthropic support
pip install duragraph-python[anthropic]

# All features
pip install duragraph-python[all]

Quick Start

from duragraph import Graph, llm_node, entrypoint

@Graph(id="customer_support")
class CustomerSupportAgent:
    """A customer support agent that classifies and responds to queries."""

    @entrypoint
    @llm_node(model="gpt-4o-mini")
    def classify(self, state):
        """Classify the customer intent."""
        return {"intent": "billing"}

    @llm_node(model="gpt-4o-mini")
    def respond(self, state):
        """Generate a response based on intent."""
        return {"response": f"I'll help you with {state['intent']}."}

    # Define flow
    classify >> respond


# Run locally
agent = CustomerSupportAgent()
result = agent.run({"message": "I have a billing question"})
print(result)

# Or deploy to control plane
agent.serve("http://localhost:8081")

Features

Decorator-Based Graph Definition

from duragraph import Graph, llm_node, tool_node, router_node, human_node

@Graph(id="my_agent")
class MyAgent:
    @llm_node(model="gpt-4o-mini", temperature=0.7)
    def process(self, state):
        return state

    @tool_node
    def search(self, state):
        results = my_search_function(state["query"])
        return {"results": results}

    @router_node
    def route(self, state):
        return "path_a" if state["condition"] else "path_b"

    @human_node(prompt="Please review")
    def review(self, state):
        return state

Prompt Management

from duragraph.prompts import prompt

@llm_node(model="gpt-4o-mini")
@prompt("support/classify_intent", version="2.1.0")
def classify(self, state):
    # Prompt is fetched from prompt store automatically
    return state

Streaming

async for event in agent.stream({"message": "Hello"}):
    if event.type == "token":
        print(event.data, end="")
    elif event.type == "node_complete":
        print(f"\nNode {event.node_id} completed")

Subgraphs

@Graph(id="research")
class ResearchAgent:
    @llm_node
    def research(self, state):
        return {"findings": "..."}

@Graph(id="main")
class MainAgent:
    research = ResearchAgent.as_subgraph()

    @entrypoint
    def plan(self, state):
        return state

    plan >> research

CLI

# Initialize new project
duragraph init my-agent

# Run locally in development mode
duragraph dev

# Deploy to control plane
duragraph deploy --control-plane http://localhost:8081

# Visualize graph
duragraph visualize my_agent.py

Configuration

# pyproject.toml
[tool.duragraph]
control_plane = "http://localhost:8081"

[tool.duragraph.llm]
default_model = "gpt-4o-mini"

[tool.duragraph.llm.providers.openai]
api_key = "${OPENAI_API_KEY}"

Documentation

Requirements

  • Python 3.10+
  • DuraGraph Control Plane (for deployment)

Contributing

Contributions are welcome! Please read our Contributing Guide.

License

Apache 2.0 - see LICENSE 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

duragraph_python-0.1.0.tar.gz (110.6 kB view details)

Uploaded Source

Built Distribution

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

duragraph_python-0.1.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file duragraph_python-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for duragraph_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d375b3ac008012f3fd55cc06cb54fb272c67ba85893830926d4151d3c0e7e40
MD5 1c1a3fc33a9e286716002709298bdcf9
BLAKE2b-256 66a21b08b7b44ca8be60a8fbee6f6f887c7f6c7ed08a211ff5bd881ac7c93ced

See more details on using hashes here.

Provenance

The following attestation bundles were made for duragraph_python-0.1.0.tar.gz:

Publisher: publish.yml on Duragraph/duragraph-python

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

File details

Details for the file duragraph_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for duragraph_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58a11f5de60cd687658632128928ccc6ed5d7bffa5d2aa01b2823693613729b3
MD5 d33ed1dbac000ca6f95c81fa7c4e1fac
BLAKE2b-256 ffe1e82f17ce71e12cba9347b42d596ad67e0baac393e8ab114b315a04ad0d05

See more details on using hashes here.

Provenance

The following attestation bundles were made for duragraph_python-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Duragraph/duragraph-python

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