Agent Actions with Hyrex

Your AI agent needs to take real actions in the world - creating tickets, sending notifications, deploying code, updating databases. But how do you make these actions reliable, scalable, and trackable? Hyrex makes it simple!

With Hyrex, you can turn any agent decision into reliable, asynchronous actions that run on distributed workers. Whether your agent needs to integrate with Slack, JIRA, GitHub, or any other service, Hyrex handles the execution complexity while you focus on the AI logic.

Agent Actions Workflow

Step 1: Define Your Action Tasks

Create Hyrex tasks for each action your AI agent might need to take. These tasks handle integrations with external services, API calls, and any complex operations that should run asynchronously and reliably.

src/hyrex/agent_tasks.py
1from hyrex import HyrexRegistry
2import requests
3import json
4
5hy = HyrexRegistry()
6
7@hy.task
8def send_slack_notification(message: str, channel: str):
9    """Send notification to Slack channel"""
10    payload = {
11        "text": message,
12        "channel": channel
13    }
14    requests.post(
15        "https://hooks.slack.com/services/YOUR/WEBHOOK/URL",
16        json=payload
17    )
18
19@hy.task
20def create_jira_ticket(title: str, description: str, assignee: str):
21    """Create a new JIRA ticket"""
22    ticket_data = {
23        "fields": {
24            "project": {"key": "PROJ"},
25            "summary": title,
26            "description": description,
27            "issuetype": {"name": "Task"},
28            "assignee": {"name": assignee}
29        }
30    }
31
32    response = requests.post(
33        "https://your-domain.atlassian.net/rest/api/3/issue",
34        json=ticket_data,
35        auth=(os.environ.get("JIRA_EMAIL"), os.environ.get("JIRA_TOKEN"))
36    )
37    return response.json()
38
39@hy.task
40def process_ai_agent_action(action_type: str, payload: dict):
41    """Process action requested by AI agent"""
42    if action_type == "notify_team":
43        send_slack_notification.send(
44            payload["message"],
45            payload["channel"]
46        )
47    elif action_type == "create_ticket":
48        create_jira_ticket.send(
49            payload["title"],
50            payload["description"],
51            payload["assignee"]
52        )
53    elif action_type == "deploy_service":
54        deploy_to_production.send(payload["service_name"])

Step 2: Create Action APIs for Your Agent

Build REST APIs that your AI agent can call to trigger actions. These endpoints queue tasks on Hyrex workers and return immediately, allowing your agent to continue processing while actions execute in the background.

src/routes/agent_api.py
1from fastapi import FastAPI
2from pydantic import BaseModel
3from .tasks import process_ai_agent_action
4
5app = FastAPI()
6
7class AgentActionRequest(BaseModel):
8    action_type: str
9    payload: dict
10    agent_id: str = None
11
12class BulkActionRequest(BaseModel):
13    actions: list[AgentActionRequest]
14
15@app.post("/agent/action")
16async def execute_agent_action(request: AgentActionRequest):
17    # Send task to process the agent's requested action
18    task = process_ai_agent_action.send(
19        request.action_type,
20        request.payload
21    )
22    return {
23        "message": "Agent action queued successfully",
24        "task_id": task.task_id,
25        "action_type": request.action_type
26    }
27
28@app.post("/agent/bulk-actions")
29async def execute_bulk_actions(request: BulkActionRequest):
30    task_ids = []
31    for action in request.actions:
32        task = process_ai_agent_action.send(
33            action.action_type,
34            action.payload
35        )
36        task_ids.append(task.task_id)
37
38    return {
39        "message": f"Queued {len(task_ids)} actions",
40        "task_ids": task_ids
41    }

Your agent is now ready for action!

Now your AI agent can trigger real-world actions reliably and at scale! Actions are queued instantly, executed by distributed workers, and you get full visibility into what's happening with task IDs and status tracking.

Want to level up? Add retry logic for failed actions, implement action approval workflows, or set up monitoring dashboards to track your agent's activity across all your integrations.