What is an Agent?
An agent is a self-contained unit of functionality in Agility. Each agent has a specific purpose: reading data from a source, processing information, or taking an action. Agents are the nodes in your workflow graph.Agent Structure
Core Definition
Every agent is defined with these properties:Agent Instance
When you add an agent to a workflow, it becomes aWorkflowElement:
Multiple instances of the same agent can exist in a workflow. Each instance has its own configuration and element ID.
Available Agents
Agility provides five built-in agents (fromagents.ts:1):
Text Generator
Purpose: Generate text using AI language modelsprompt: The text generation prompt (supports placeholders)model: AI model to use (e.g., “gpt-4”, “gpt-3.5-turbo”)apiKey: OpenAI API keyprovider: AI provider (default: “openai”)
- Summarizing emails
- Generating responses
- Content transformation
- Data extraction
Gmail Reader
Purpose: Read emails from a Gmail accountfromEmail: Filter by sender email addressmaxResults: Maximum number of emails to retrieveonlyUnread: Whether to only fetch unread emails
outputContext.input):
emailBody: Body of the first emailemailSubject: Subject of the first emailemailFrom: Sender of the first emailemailTo: Recipient of the first emailemailDate: Date of the first emailemail: Formatted email string (From/To/Subject/Date/Body)
Gmail Sender
Purpose: Send emails through Gmailto: Recipient email address (supports placeholders)subject: Email subject line (supports placeholders)body: Email body content (supports placeholders)
Discord Messenger
Purpose: Send messages to Discord servers via webhookswebhookUrl: Discord webhook URLcontentormessageContent: Message text (supports placeholders)username: Custom bot username (optional)avatarUrl: Custom bot avatar URL (optional)
GitHub Reader
Purpose: Read push changes from a GitHub repositoryaccessToken: GitHub personal access tokenrepository: Repository in format “owner/repo”branch: Branch to monitor (default: “main”)
outputContext.input):
repoName: Repository namebranch: Branch namecommits: Array of commit objectssummary: Summary of changespusher: User who pushed the changes
Agent Categories
Agents fall into three functional categories:1. Input Agents (Triggers)
Read data from external sources:- Gmail Reader: Fetches emails
- GitHub Reader: Monitors repository changes
2. Processing Agents
Transform or analyze data:- Text Generator: Uses AI to process text
3. Output Agents (Actions)
Send data to external services:- Gmail Sender: Sends emails
- Discord Messenger: Posts to Discord
Agent Configuration
Configuration Storage
Each agent instance stores its configuration in theagent_configs table:
Agent Type Naming
Agent types use snake_case derived from the display name:Configuration Retrieval
During execution, the workflow engine fetches configuration:Agent Execution
Execution Process
- Configuration Loading: Fetch agent configuration from database
- Placeholder Resolution: Replace
{{input.*}}patterns with actual values - Agent Execution: Call the agent’s cloud function
- Context Storage: Store output in the workflow context
- Error Handling: Capture and store any errors
Example: Text Generator Execution
Fromrun-workflow/index.ts:384:
Context Storage Strategy
Each agent stores output in two places:- Element-specific:
outputContext[elementId]- Full output object - Input namespace:
outputContext.input.*- Convenience fields
- Explicit references:
{{input.text}}(simple) - Element-specific references: Could reference specific element outputs (advanced)
Output Structures
Agents define their output structure for type safety:- Auto-completion for placeholders
- Type checking in configurations
- Visual data flow indicators
Best Practices
Configure Agents Before Connecting
Configure Agents Before Connecting
Set up and test each agent’s configuration before adding connections. This prevents workflow execution errors.
Use Descriptive Configuration Values
Use Descriptive Configuration Values
When possible, use clear, self-documenting values in your configuration. For example:
Store Sensitive Data Securely
Store Sensitive Data Securely
API keys and tokens are stored in the database. Never hardcode them in your application code.
Test with Sample Data First
Test with Sample Data First
Use test recipient emails, sandbox Discord webhooks, and test repositories before running production workflows.
Monitor Agent Outputs
Monitor Agent Outputs
Check the execution results to understand what data each agent produces. This helps write better placeholder expressions.
Error Handling
Agents handle errors gracefully:Configuration Errors
Execution Errors
Advanced Topics
Custom Agent Development
While not directly supported in the current version, the architecture allows for custom agents by:- Adding agent definition to
agents.ts - Creating a Supabase Edge Function
- Adding execution logic to
run-workflow/index.ts
Agent Reusability
The same agent definition can be instantiated multiple times in a workflow:Next Steps
Workflows
Learn how agents connect together in workflows
Connections
Understand how data flows between agents