Agents async API
This cookbook provides a step-by-step guide to use the asynchronous API for DevRev agents. It assumes you’ve already created an agent using the DevRev agent builder platform.
The DevRev async API enables you to execute agents without any execution timeout concerns. The execution occurs as an asynchronous workflow that sends events to you via webhooks. This approach ensures:
- Agent complexity does not bring timeout concerns with it.
- Complete execution tracking via progress events.
- Ability to handle long-running agent tasks.
In any unlikely and unforeseen circumstances, if an individual operation of the workflow times out, you do not receive an error event right now to notify that you should not wait for any more messages. It is better to have a client side timeout for now while the issue is brainstormed and fixed for you.
Set up webhook
Before using the async API, you need to create a webhook to receive agent execution events:
Save the webhook ID from the response (format: don:integration:dvrv-us-1:devo/0:webhook/auCJ7By8
). You need this when making async API calls.
Make sure that your webhook endpoint can appropriately respond to the verify events sent by DevRev to verify your webhook. This verify event has a challenge string which you need to return in response. You return the response like this:
You should follow the documentation provided for webhooks here
Make async API calls
Key parameters:
agent
: Your agent’s ID.event.input_message.message
: The query for your agent.session_object
: A unique identifier for the conversation session (maintains agent memory).webhook_target.webhook
: The webhook ID created earlier.
To execute an agent asynchronously:
The session_object parameter is critical for maintaining conversation state across multiple calls.
Handle webhook events
Your webhook endpoint receives three types of events.
Progress messages
These show which skills are being triggered and executed.
Final message
This event contains the agent’s final response after all skills are executed.
Error message
This event indicates an error occurred during execution.
Implementation patterns
Custom applications
This pattern is ideal for custom chat interfaces, backend systems, or any application that needs to interact with DevRev agents.
For building custom applications with the async API:
- Create a webhook endpoint in your application that can receive POST requests.
- Register this endpoint with DevRev using the webhooks.create API.
- Make async API calls with your agent ID and webhook ID.
- Process incoming webhook events to:
- Track progress (optional).
- Display the final agent response to the user.
- Handle any errors.
Example flow for a chat application:
Using WebSockets or Server-Sent Events can provide real-time updates to your UI as events are received.
Talk to agent node in workflows
This is in early access, please contact support to have it enabled for you.
If you’re using DevRev workflows:
The workflow engine handles the async API calls for you when using the Talk To Agent node.
- Add the “Talk To Agent” node to your workflow
- Configure it with your agent ID
- Connect it to response nodes to process the agent’s output
- The async API is used automatically by the workflow engine
Troubleshooting
Not receiving webhook events?
- Verify your webhook URL is publicly accessible
- Check that you’ve registered for the “ai_agent_response” event type
- Ensure your server responds with a 2xx status code quickly
Execution errors?
- Check the error message in the error event
- Verify your agent ID is correct
- Ensure your session_object is a valid string
Agent not responding as expected?
- Review the skill_triggered and skill_executed events to see which skills were invoked
- Check if any skills returned error outputs
- Verify your agent’s configuration in the DevRev agent builder