---
question: How do I expose a workflow as agent tools?
kind: task
via_web: na
via_cli: na
via_python: available
via_api: na
via_config: na
ref_python: as_tools()
prereq: You need a workflow class in a module, or another module's durable workflow. [Create a workflow](/capabilities/build/agents/creating-a-workflow) first.
next:
  - /capabilities/build/agents/give-it-tools
  - /capabilities/build/workflows/test-a-workflow
  - /capabilities/build/agents/test-an-agent
---

# Expose as a tool

An agent calls a workflow through LangChain tools. Where they come from depends on where the workflow lives:

| Workflow | Tools | Runs |
|---|---|---|
| A class of the agent's module | `self.get_workflow_instance(name).as_tools()`: one tool, from the base class | `run` on the module's loop |
| A durable workflow of another module | `WorkflowProxy.as_tools()`: one tool | A durable run, recorded in System › Jobs |

## Web UI

Not applicable. Nexus cannot attach a workflow's tools to an agent: they are set in Python, in the module's `on_initialized`. Use the Python steps on this page.

## CLI

Not applicable. No command adds a tool. The class that `abi new workflow` writes has its tool already.

## Python

### Build the classes first

A workflow class comes with one tool: named by the class slug (`customers_workflow`), described by the class docstring, taking the parameters model. A Pydantic result comes back as JSON data. An agent takes its tools when it is built, in `on_initialized`, and the module builds its classes after that hook: call `await self.build_processes()` first.

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

`build_processes()` builds the classes that are not built yet, so bind the ones that need arguments with `self.expose_workflow(name, instance)` before it. `as_tools()` needs `naas-abi-sdk[agents]`. `create_agent` is the function `abi new module` writes in `agents/`; keep its `chat_model=` argument, or the agent falls back to the engine's default model.

The parameters model is the tool's argument schema, so its `Field(description=...)` texts tell the model how to fill each argument. Write the class docstring for the model: it decides from it when to call the tool.

### Give an agent another module's workflow

`WorkflowProxy.as_tools()` returns one tool that starts the workflow as a durable run and returns its output. It is named after the last part of the workflow's name (`workflow.lookup_workflow` is `lookup_workflow`). Its description and its arguments come from the descriptor the proxy holds, so get the proxy from a lookup that reads the declared workflow:

| Proxy from | Tool description and arguments |
|---|---|
| `await self.engine.modules[id].get_workflow(name)` (discovery) | The workflow's description and input schema |
| `self.get_workflow(name)`, the module's own workflow | The workflow's description and input schema |
| `ABIClient(...).get_workflow(...)` | None: the proxy holds only the name, so the tool has no description and an empty argument schema, and the agent cannot fill the input. `input_type=` checks a start but does not change the tool. |

```python title="src/reports/__init__.py"
async def on_initialized(self) -> None:
    # acme.items is listed in ModuleDependencies(modules=...)
    lookup = await self.engine.modules["acme.items"].get_workflow("workflow.lookup_workflow")
    agent = await create_agent(
        self.engine, MODULE_ID, chat_model=self.configuration.chat_model, tools=lookup.as_tools()
    )
    self.expose_agent(NAME, agent.as_handler())
```

The module's own `self.get_workflow(name)` raises `JobsNotHosted` until `on_initialized` has returned: in that hook, give an agent the class's own tool instead, as in the step above.

Create the tool inside the running module: its sync call runs on the loop it was created on. Each call is a recorded run, with the workflow's limits: one run at a time for a published class, unless its `job` says otherwise.

### Restart and try it

Restart the module, then ask the agent for that intent in Nexus chat. See [Test an agent](/capabilities/build/agents/test-an-agent).

## REST API

Not applicable. A tool is agent-internal: the API gives a LangChain tool no route. To start the workflow over HTTP, see [Expose as an API](/capabilities/build/workflows/expose-as-an-api).

## Config

Not applicable. Which tools an agent has is set in Python, in the module's `on_initialized`, not in `config.yaml`.
