Adding Agent Tools to Duckie
Steps
To create an Agent Tool:
- Create an API endpoint – Define endpoints for data retrieval or processing (e.g. using FastAPI).
- Deploy the API – Make it publicly accessible using Docker, Railway, Fly.io, AWS, or your preferred hosting service.
- Add it to Duckie’s Agent Tools – Register the API in Duckie’s Agent Tools.
- Add to a Workflow – Put the Agent Tool as a node in your workflow. Duckie will invoke it when handling tickets, based on the workflow logic you’ve set.
For a live demo of creating a new Agent Tool, see the following Loom Video.
Example: Build and Deploy an API Wrapper for Datadog
- Create the API wrappers
- Retrieve a container ID using a
caller_id
.
- Fetch logs based on the container ID, filtering with specific keywords.
- Deploy the API for external use and expose it publicly.
1. Setup and Prerequisites
Install Dependencies
Ensure you have Python installed, then install the required packages:
pip install fastapi uvicorn requests datadog-api-client
### Datadog API Credentials
Obtain your **Datadog API Key** and **Application Key** from the [Datadog API Key Management](https://app.datadoghq.com/organization-settings/api-keys).
## 2. Writing the API Wrapper
**Please note that these are templates for references only, the logic will need to be modified for your particular use case.**
Create a file `api.py`:
```python
from fastapi import FastAPI, HTTPException, Header, Query
import requests
app = FastAPI()
DATADOG_API_KEY = "your_api_key"
DATADOG_APP_KEY = "your_app_key"
DATADOG_LOGS_URL = "https://api.datadoghq.com/api/v2/logs/events/search"
# Step 1: Retrieve container ID
@app.get("/get-container")
def get_container_id(caller_id: str, x_api_key: str = Header(None)):
response = requests.get(DATADOG_LOGS_URL, headers={
"DD-API-KEY": DATADOG_API_KEY,
"DD-APPLICATION-KEY": DATADOG_APP_KEY
}, params={
"query": f"caller_id:{caller_id}",
"sort": "desc"
})
logs = response.json().get("data", [])
if not logs:
raise HTTPException(status_code=404, detail="No logs found for caller_id")
container_id = logs[0].get("attributes", {}).get("container_id", "Unknown")
return {"container_id": container_id}
# Step 2: Fetch logs with filters
@app.get("/get-logs")
def get_logs(container_id: str, tool_keyword: str = Query(None), x_api_key: str = Header(None)):
response = requests.get(DATADOG_LOGS_URL, headers={
"DD-API-KEY": DATADOG_API_KEY,
"DD-APPLICATION-KEY": DATADOG_APP_KEY
}, params={
"query": f"container_id:{container_id} {tool_keyword if tool_keyword else ''}",
"sort": "desc"
})
logs = response.json().get("data", [])
return {"logs": logs}
3. Deploying the API
Option 1: Deploy with Docker
Create a Dockerfile
:
FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install fastapi uvicorn requests datadog-api-client
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
Build and run locally:
docker build -t datadog-api-wrapper .
docker run -p 8000:8000 datadog-api-wrapper
Option 2: Deploy on Railway or Fly.io (Easiest)
For Railway:
For Fly.io:
Option 3: Deploy on AWS with API Gateway for Public Access
- Deploy FastAPI as an AWS Lambda function with API Gateway.
- Use
Mangum
to convert FastAPI into an AWS Lambda-compatible app.
- Open API Gateway settings and enable public access.
Modify api.py:
from mangum import Mangum
handler = Mangum(app)
Then deploy using AWS SAM or Terraform.
Once your API is live, register it as an Agent Tool in Duckie by filling out the following fields:
- Name – A clear name for the tool (e.g. “Stripe Refund Processor”, “Datadog Log Fetcher”).
- Approval Required? – Check this if you want the tool’s output to require manual approval before Duckie can use it. If yes, Duckie will send an internal note in Zendesk/Intercom to the admin asking for approval, and then proceed to execute the API call after receiving confirmation.
- Description – Describe what the tool does and when it should be used.
- Endpoint – The full URL of your API endpoint.
- Method – The HTTP method used to call the API (e.g. GET, POST).
- Headers – Any headers Duckie should include in the request (e.g. API keys).
- Parameter List – The parameters Duckie should pass when calling the API (e.g.
customer_id
, order_id
).
Once configured, your Agent Tool can be added to workflows to let Duckie invoke it as part of handling tickets.
5. Add to Workflow
After creating your Agent Tool, you can add it as a node in any Duckie workflow. This allows Duckie to automatically call the tool at the right moment during ticket handling.
When adding to a workflow:
- Choose the custom node type in the workflow builder.
- Select the specific tool you registered.
- [Optional] Map variables or outputs from earlier nodes (e.g.
customer_id
, order_id
) to the tool’s parameters.
- Define what happens next based on the tool’s response (e.g. send a message, trigger another tool, escalate).

Responses are generated using AI and may contain mistakes.