Working with Agents
Learn how to create, configure, and deploy AI agents using Weni CLI.
Agent Definition File
Agents are defined using YAML files. Here's the basic structure:
agents:
agent_id:
name: "Agent Name"
description: "Agent Description"
instructions:
- "Instruction 1"
- "Instruction 2"
guardrails:
- "Guardrail 1"
tools:
- tool_name:
name: "Tool Name"
source:
path: "tools/tool_name"
entrypoint: "main.ToolClass"
description: "Tool Description"
parameters:
- param_name:
description: "Parameter Description"
type: "string"
required: true
contact_field: true
Key Components
- Agent ID
- Unique identifier for your agent
-
Used internally by the system
-
Basic Information
name: Display name (max 55 characters)-
description: Brief description of the agent's purpose -
Instructions
- Guide the agent's behavior
- Minimum 40 characters each
-
Should be clear and specific
-
Guardrails
- Define boundaries and limitations
-
Prevent unwanted behavior
-
Tools
- Custom functionalities
- Implemented as Python classes using the Weni SDK
Tool Source Configuration
The source field is critical for locating and executing your tool:
- path: Points to the directory containing your tool implementation
- Example:
tools/get_addressrefers to a folder namedget_addressinside atoolsdirectory -
This folder should contain your Python modules and requirements.txt
-
entrypoint: Specifies which class to use in which file
- Format:
filename.ClassName - Example:
main.GetAddressmeans:- Look for a file named
main.pyin the path directory - Find a class named
GetAddressinside that file - This class must inherit from the
Toolclass
- Look for a file named
Your directory structure should look like:
project/
├── agents.yaml
└── tools/
└── get_address/
├── main.py # Contains GetAddress class
└── requirements.txt # Dependencies
Creating Tools
Tool Implementation Structure
from weni import Tool
from weni.context import Context
from weni.responses import TextResponse
class ToolName(Tool):
def execute(self, context: Context) -> TextResponse:
# Extract parameters
parameters = context.parameters
param_value = parameters.get("param_name", "")
# Process the request
result = self.process_request(param_value)
# Return response
return TextResponse(data=result)
def process_request(self, param_value):
# Your business logic here
return {"key": "value"}
Important Requirements
- The class must inherit from
Tool - The class must implement the
executemethod - The class name must match the class name in your entrypoint
Deploying Agents
Push Command
Deploy your agent using:
The command:
- Validates your YAML
- Uploads tools
- Creates/updates the agent
Elastic APM instrumentation (passive agents only)
For passive agents (tools deployed as AWS Lambdas), you can control Elastic APM instrumentation at push time:
| Flag | Behavior |
|---|---|
| (none) | Preserves the current APM state on each tool Lambda |
--use-apm |
Enables APM layers and environment variables on all tool Lambdas in the definition |
--remove-apm |
Removes APM instrumentation from all tool Lambdas in the definition |
# Enable APM on tool Lambdas
weni project push agents.yaml --use-apm
# Remove APM from tool Lambdas
weni project push agents.yaml --remove-apm
# Deploy without changing APM state
weni project push agents.yaml
Important:
--use-apmand--remove-apmcannot be used together.- These flags apply only to passive agents. They are ignored for active agent pushes.
- APM affects all tools in the agent definition file for that push.
Warning — use APM only for observability
Enable APM only when you need to observe or debug tool Lambda behavior. APM adds layers and environment variables that increase cold start time and runtime overhead, which can degrade Lambda performance.
When investigation is complete, disable APM so production traffic is not affected:
After a successful push with --use-apm, the CLI displays the same warning in the terminal.
Deployment Best Practices
- Version Control
- Keep agent definitions in version control
-
Document changes
-
Testing
- Test locally when possible
- Start with staging environment
-
Verify all tools work
-
Organization
- Use clear file names
- Keep related files together
- Document dependencies
Advanced Topics
Parameter Types
Available parameter types:
- string
- number
- integer
- boolean
- array
Response Formats
Tools can return:
- Text responses via TextResponse
- Structured data
- Error messages
Error Handling
Your tools should: 1. Validate inputs 2. Handle exceptions gracefully 3. Return meaningful error messages
Troubleshooting
Common Issues
- Deployment Failures
- Check YAML syntax
- Verify tool paths
-
Confirm project selection
-
Tool Errors
- Verify tool entrypoint (class name)
- Test tool class locally
- Check parameter handling in context
-
Verify API endpoints
-
Agent Behavior
- Review instructions
- Check guardrails
- Test with various inputs
Best Practices
- Development Flow
- Develop locally
- Test in staging
-
Deploy to production
-
Monitoring
- Keep deployment logs
- Monitor tool performance
-
Track user interactions
-
Updates
- Plan changes carefully
- Test updates thoroughly
- Document modifications