---
question: How do I attach an integration as agent tools?
kind: task
via_web: na
via_cli: na
via_python: available
via_api: na
via_config: na
ref_python: as_tools(configuration)
prereq: You need an integration with an `as_tools(configuration)` function, a credential [in the secret service](/capabilities/build/integrations/add-credentials), and an agent in the same module. See [Create an agent](/capabilities/build/agents/creating-an-agent).
next:
  - /capabilities/build/integrations/test-an-integration
  - /capabilities/build/agents/give-it-tools
---

# Use in an agent

An agent uses an integration through tools. By convention, each integration file defines a module-level `as_tools(configuration)` function that returns LangChain `StructuredTool`s. The `Integration` base class has no such method. An agent takes its tools when it is built, in the module's `on_initialized`: read the key, call `as_tools`, and pass the tools to the agent.

## Web UI

Not applicable. Agents added in Settings › Agents are workspace agents: a name, a system prompt and a model, with no tools. Wire an integration in the module with Python.

## CLI

Not applicable. No `abi` command adds tools to an agent. Write it in Python, then chat with the agent in Nexus to try the tools.

## Python

### Declare the secret service

The module reads the key from the engine secret service, so it lists `"secret"` in its dependencies:

```python title="src/my_module/__init__.py"
dependencies = ModuleDependencies(
    services=("model_registry", "document", "triple_store", "secret")
)
```

### Build the tools in on_initialized

```python title="src/my_module/__init__.py"
from my_module.integrations.MyIntegration import MyIntegrationConfiguration, as_tools


class ABIModule(BaseModule[MyModuleConfiguration]):
    ...

    async def on_initialized(self) -> None:
        tools: list = []
        api_key = await self.engine.services.secret.get("MY_API_KEY")
        if api_key:
            tools += as_tools(MyIntegrationConfiguration(api_key=api_key))
        agent = await create_agent(
            self.engine, MODULE_ID, chat_model=self.configuration.chat_model, tools=tools
        )
        self.expose_agent(NAME, agent.as_handler())
```

`create_agent` is the function `abi new agent` writes in `agents/<Name>Agent.py`: it takes `tools=` and passes them to the SDK `IntentAgent`. `get` returns `None` when no adapter has the key, so the agent starts without those tools, and gets them at the module's next start after you [add the key](/capabilities/build/integrations/add-credentials).

### Add the module's workflows too

An agent can take a workflow's tools in the same list. Build the workflows first, since they are otherwise built after `on_initialized`:

```python
await self.build_processes()
tools += self.get_workflow_instance("items_workflow").as_tools()
```

### Try it

Restart the module. Once it logs `READY`, its agent is listed in Nexus with the engine's: open a chat with it and ask for something only the integration can answer. See [Chat with an agent](/capabilities/build/agents/chat-with-an-agent).

## REST API

Not applicable. There is no HTTP call that adds tools to an agent. Tools are wired when the module builds the agent.

## Config

Not applicable. The key is in the secret service (see [Add credentials](/capabilities/build/integrations/add-credentials?via=config)), not in a list of tools. The tools are wired in `on_initialized`.

## Which tools the agent sees

`as_tools` decides the tool names, descriptions and argument schemas. The model picks a tool from its description, so write it for the model: what the tool does and when to use it. The tool schemas are on [Create an integration](/capabilities/build/agents/creating-an-integration#expose-it-as-tools). Workflows and other agents as tools are on [Give it tools](/capabilities/build/agents/give-it-tools).
