This guide explains how to create Python-based UiPath Coded Agents that respond to event triggers, enabling seamless event-driven agents.
UiPath Coded Agents allow you to write automation logic directly in Python while leveraging UiPath's event trigger system. This project demonstrates how to create agents that handle external events from systems like Gmail, Slack, and other connectors.
- Open it with your prefered editor
- In terminal run:
uv init
uv add uipath
uv run uipath new event-agent
uv run uipath initCreate a Python file with your agent logic using the UiPath SDK:
from dataclasses import dataclass
from uipath.platform import EventArguments
from uipath import UiPath
import logging
logger = logging.getLogger(__name__)
@dataclass
class EchoOut:
message: dict
# use EventArguments when called by UiPath EventTriggers
def main(input: EventArguments) -> EchoOut:
sdk = UiPath()
# get the event payload, this will be different from event to event
payload = sdk.connections.retrieve_event_payload(input)
logger.info(f"Received payload: {payload}")
return EchoOut(payload)Run uipath init again to update the input arguments.
When an event trigger fires, UiPath will:
- Pass event data through
EventArguments - Your agent retrieves the full payload using
sdk.connections.retrieve_event_payload(input) - Process the payload based on your business logic
- Return structured output
- Use
uipath packanduipath publishto create and publish the package - Create an Orchestrator Automation from the published process
- Log into UiPath Orchestrator
- Navigate to Automations → Processes
- Click on your coded workflow process
- Go to the Triggers tab
- Click Add Trigger → Event Trigger
- Name: Descriptive name (e.g., "Gmail Event Handler")
- Event Source: Select connector type:
uipath-google-gmailcustomfor Gmailuipath-slackfor Slackuipath-microsoft-outlookcustomfor Outlook- Custom connectors
- Event Type: Choose specific event:
EMAIL_RECEIVEDfor emailsMESSAGE_RECEIVEDfor chat messages- Custom event types
- Filters: Optional event filtering criteria
The event data will automatically be passed to your EventArguments parameter.
- Review configuration
- Click Create to save
- Ensure trigger status is Enabled
- Send test email (Gmail triggers)
- Post message in Slack (Slack triggers)
- Perform action matching your event source
- Check Monitoring → Jobs in Orchestrator
- View job details and execution logs
- Verify your coded agent processed the event correctly
import logging
logger = logging.getLogger(__name__)
def main(input: EventArguments) -> EchoOut:
sdk = UiPath()
# payload will be a json (dict) specific to your event
payload = sdk.connections.retrieve_event_payload(input)
logger.info(f"Successfully retrieved payload: {type(payload)}")
logger.debug(f"Payload details: {payload}")
# Your processing logic here
result = process_event(payload)
logger.info(f"Event processed successfully: {result}")
return EchoOut(result)