---
question: Which callers do I edit before deleting a workflow?
kind: task
via_web: na
via_cli: available
via_python: available
via_api: na
via_config: na
ref_cli: git rm
ref_python: Workflow
prereq: The workflow is a `<Name>Workflow.py` file in the `workflows/` folder of a module of your project. A `@workflow` method is deleted like any method of the module.
next:
  - /capabilities/build/workflows/overview
  - /capabilities/build/agents/creating-a-workflow
  - /capabilities/build/agents/give-it-tools
---

# Delete a workflow

A workflow exists because its class sits in the module's `workflows/` folder, or in `workflows = (...)` on the module class. Delete the class and what refers to it, then restart the module. What goes with it:

- the class and its agent tool;
- its durable workflow `workflow.<slug>`, with the triggers the class set in `job = JobSettings(...)`.

Its run records stay in System › Jobs until they are pruned, after 7 days. A caller that still names `workflow.<slug>` breaks in one of two ways, depending on how it looks the workflow up:

- **The lookup fails.** The module's own `self.get_workflow("workflow.customers_workflow")` raises `ValueError`, and another module's `await self.engine.modules[id].get_workflow(...)` raises `RPCError` with `WORKFLOW_NOT_FOUND`. A module that does that second lookup in `on_initialized`, for example to give an agent the workflow's tool, then fails to start.
- **The start waits for ever.** `ABIClient(...).get_workflow(...)` and `ctx.call(...)` check nothing before they start: the run stays `QUEUED`, since no module takes it, and a parent that called it waits until its own timeout. Nexus answers 404.

## Web UI

Not applicable. Nexus has no screen that deletes a workflow: a workflow is code in a module. Use the CLI or Python steps on this page. After the restart, System › Jobs marks it as no longer declared by any module.

## CLI

### Find what uses it

From the project root:

```bash
grep -rn "CustomersWorkflow" src/
```

Agents that get its tool, other workflows that compose it, and modules that bind it with `expose_workflow` all name the class. Callers by name do not: search for the slug too.

```bash
grep -rn "customers_workflow" src/
```

That finds `get_workflow("workflow.customers_workflow")`, `ctx.call(..., "workflow.customers_workflow", ...)` and `get_workflow_instance("customers_workflow")`.

### Edit the callers

Change each file the search found before deleting the class, as in the [Python steps](/capabilities/build/workflows/delete-a-workflow?via=python).

### Remove the files

`abi new workflow` writes the class and a test beside it. Remove both:

```bash
git rm src/reports/workflows/CustomersWorkflow.py src/reports/workflows/CustomersWorkflow_test.py
```

### Restart the module

The module finds its workflows when it starts. With `abi dev up`, restart the stack:

```bash
abi dev down
abi dev up
```

With Docker Compose, run `abi stack stop`, then `abi stack start`. A module deployed on its own restarts with its container. The commands are [`abi dev`](/user-guide/reference/cli#abi-dev) and [`abi stack`](/user-guide/reference/cli#abi-stack).

### Check it is gone

`GET /api/workflows` no longer lists `workflow.customers_workflow`. In System › Jobs, its past runs stay, and the workflow is marked as no longer declared by any module.

## Python

### Remove its tool from the agents

Drop the `as_tools()` call from `on_initialized`, where the module builds its agents:

```python title="src/reports/__init__.py"
async def on_initialized(self) -> None:
    await self.build_processes()
    # Removed:
    # tools = self.get_workflow_instance("customers_workflow").as_tools()
    agent = await create_agent(
        self.engine, MODULE_ID, chat_model=self.configuration.chat_model
    )
    self.expose_agent(NAME, agent.as_handler())
```

Do this before deleting the class: `get_workflow_instance` raises `ValueError` for a workflow the module no longer builds, and the module fails to start.

### Remove the other callers

Workflows that call it with `get_workflow_instance`, and durable workflows that start it with `ctx.call`, need another source for that result, or go too. Also drop the `self.expose_workflow(...)` call or the `workflows = (...)` entry that names the class: both import it, so the module would fail at startup.

### Delete the class

Delete `workflows/CustomersWorkflow.py` and `CustomersWorkflow_test.py`, then restart the module as in the [CLI steps](/capabilities/build/workflows/delete-a-workflow?via=cli).

## REST API

Not applicable. No endpoint deletes a workflow: Nexus lists the workflows the modules declare. Once the class is gone and the module restarted, `POST /api/workflows/{module_id}/workflow.<slug>/runs` answers 404.

## Config

Not applicable. `config.yaml` has no switch for one workflow: the class is code in the module.
