{"id":18261581,"url":"https://github.com/dbos-inc/durable-swarm","last_synced_at":"2026-03-13T19:03:11.141Z","repository":{"id":258411065,"uuid":"873106032","full_name":"dbos-inc/durable-swarm","owner":"dbos-inc","description":"Augment Swarm with durable execution to help you build reliable and scalable multi-agent systems.","archived":false,"fork":false,"pushed_at":"2024-11-05T19:46:21.000Z","size":3213,"stargazers_count":96,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T23:48:24.539Z","etag":null,"topics":["agentic-workflow","ai","dbos","openai","postgresql","python","serverless"],"latest_commit_sha":null,"homepage":"https://docs.dbos.dev","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbos-inc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-15T15:57:52.000Z","updated_at":"2025-04-02T21:22:10.000Z","dependencies_parsed_at":"2024-10-21T22:39:44.655Z","dependency_job_id":null,"html_url":"https://github.com/dbos-inc/durable-swarm","commit_stats":null,"previous_names":["dbos-inc/durable-swarm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbos-inc%2Fdurable-swarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbos-inc%2Fdurable-swarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbos-inc%2Fdurable-swarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbos-inc%2Fdurable-swarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbos-inc","download_url":"https://codeload.github.com/dbos-inc/durable-swarm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317722,"owners_count":21083528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agentic-workflow","ai","dbos","openai","postgresql","python","serverless"],"created_at":"2024-11-05T11:03:22.959Z","updated_at":"2026-03-13T19:03:11.132Z","avatar_url":"https://github.com/dbos-inc.png","language":"Python","funding_links":[],"categories":["Uncategorized","Python"],"sub_categories":["Uncategorized"],"readme":"![Durable Swarm Logo](assets/durable-swarm-banner.png)\n\n# DurableSwarm: Reliable Multi-Agent Orchestration\n\n\u003e [!IMPORTANT]\n\u003e DurableSwarm is now replaced by the [DBOS Durable OpenAI Agents SDK](https://github.com/dbos-inc/dbos-openai-agents) integration, which is a production-ready evolution of DurableSwarm. We recommend migrating to the Agents SDK for all production use cases.\n\nThis repository augments [OpenAI's Swarm](https://github.com/openai/swarm) with **durable execution** to help you build **reliable** multi-agent systems.\n\nDurable Swarm is a drop-in replacement for Swarm that makes your agentic workflows **resilient to any failure**, so that if they are interrupted or restarted, they automatically resume from their last completed steps.\nUnder the hood, it uses [DBOS](https://github.com/dbos-inc/dbos-transact-py) to persist your agentic workflows' execution state (which workflows are currently executing and which steps they've completed) in a Postgres database.\n\n## Why Durable Execution?\n\nAs multi-agent workflows become more common, longer-running, and more interactive, it's important to make them **reliable**.\nIf an agent spends hours waiting for user inputs or processing complex workflows, it needs to be resilient to transient failures, such as server restarts.\nHowever, reliable multi-agent orchestration isn't easy\u0026mdash;it requires complex rearchitecting like routing agent communication through SQS or Kafka.\n\nDurable execution helps you write reliable agents while preserving the **ease of use** of a framework like Swarm.\nThe idea is to automatically persist the execution state of your Swarm workflow in a Postgres database.\nThat way, if your program is interrupted, it can automatically resume your agentic workflows from their last completed steps.\n\n\n## Making Swarm Durable\n\nTo add Durable Swarm to your project, simply create a `durable_swarm.py` file containing the following code:\n\n```python\nfrom swarm import Swarm\nfrom dbos import DBOS, DBOSConfiguredInstance\n\nDBOS()\n\n@DBOS.dbos_class()\nclass DurableSwarm(Swarm, DBOSConfiguredInstance):\n    def __init__(self, client=None):\n        Swarm.__init__(self, client)\n        DBOSConfiguredInstance.__init__(self, \"openai_client\")\n\n    @DBOS.step()\n    def get_chat_completion(self, *args, **kwargs):\n        return super().get_chat_completion(*args, **kwargs)\n\n    @DBOS.step()\n    def handle_tool_calls(self, *args, **kwargs):\n        return super().handle_tool_calls(*args, **kwargs)\n\n    @DBOS.workflow()\n    def run(self, *args, **kwargs):\n        return super().run(*args, **kwargs)\n\nDBOS.launch()\n```\n\nThen use `DurableSwarm` instead of `Swarm` in your applications\u0026mdash;it's a drop-in replacement.\n\nUnder the hood, this works by declaring Swarm's main loop to be a durably executed workflow and each chat completion or tool call to be a step in that workflow.\nDBOS persists the input of a workflow and the outputs of its steps in a Postgres database.\nTherefore, if your workflow is ever interrupted, DBOS can automatically resume it from the last completed step!\n\n## Getting Started\n\nTo get started, install [Swarm](https://github.com/openai/swarm/tree/main) and [DBOS](https://github.com/dbos-inc/dbos-transact-py) and initialize DBOS. Swarm requires Python \u003e=3.10.\n\n```\npip install dbos git+https://github.com/openai/swarm.git\ndbos init --config\n```\n\nYou also need an OpenAI API key. You can obtain one [here](https://platform.openai.com/api-keys). Set it as an environment variable:\n\n```\nexport OPENAI_API_KEY=\u003cyour-key\u003e\n```\n\nTo try Durable Swarm out, create `durable_swarm.py` as above then create a `main.py` file in the same directory containing this simple program:\n\n```python\nfrom swarm import Agent\nfrom durable_swarm import DurableSwarm\n\nclient = DurableSwarm()\n\ndef transfer_to_agent_b():\n    return agent_b\n\n\nagent_a = Agent(\n    name=\"Agent A\",\n    instructions=\"You are a helpful agent.\",\n    functions=[transfer_to_agent_b],\n)\n\nagent_b = Agent(\n    name=\"Agent B\",\n    instructions=\"Only speak in Haikus.\",\n)\n\nresponse = client.run(\n    agent=agent_a,\n    messages=[{\"role\": \"user\", \"content\": \"I want to talk to agent B.\"}],\n)\n\nprint(response.messages[-1][\"content\"])\n```\n\nDBOS requires Postgres.\nIf you already have a Postgres server, modify `dbos-config.yaml` to configure its connection information.\nOtherwise, we provide a [script](./start_postgres_docker.py) to start Postgres using Docker:\n\n```\nexport PGPASSWORD=swarm\npython3 start_postgres_docker.py\n```\n\nFinally, run your agents:\n```\n\u003e python3 main.py\n\nAgent B is here,\nReady to help you today,\nWhat do you need, friend?\n```\n\n## Converting Existing Apps to DurableSwarm\n\nYou can convert any existing Swarm app to DurableSwarm in three simple steps:\n\n1. Install `dbos` and initialize it with `dbos init --config`.\n2. Add [`durable_swarm.py`](durable_swarm.py) to your project.\n3. Use `DurableSwarm` in place of `Swarm` in your application.\n\n\u003e [!NOTE]\n\u003e DurableSwarm currently doesn't support streaming\n\n## Examples\n\nWe created an example app using Durable Swarm to build a durable refund agent that automatically recovers from interruptions while processing refunds.\nCheck it out [here](examples/reliable_refund/) or watch this GIF of the app in action:\n\n![Durable Swarm Demo](assets/demo.gif)\n\nWe also converted each of the original Swarm examples to DurableSwarm. Find them in `examples/` and learn more about each one in its README.\n\n- [`basic`](examples/basic/): Simple examples of fundamentals like setup, function calling, handoffs, and context variables\n- [`triage_agent`](examples/triage_agent/): Simple example of setting up a basic triage step to hand off to the right agent\n- [`weather_agent`](examples/weather_agent/): Simple example of function calling\n- [`airline`](examples/airline/): A multi-agent setup for handling different customer service requests in an airline context\n- [`support_bot`](examples/support_bot/): A customer service bot which includes a user interface agent and a help center agent with several tools\n\n\u003e [!NOTE]\n\u003e We didn't convert demos that aren't yet complete, like [`personal_shopper`](https://github.com/openai/swarm/issues/49).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbos-inc%2Fdurable-swarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbos-inc%2Fdurable-swarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbos-inc%2Fdurable-swarm/lists"}