start() and chat() methods, plus optional guardrails for validation.
Quick Start
Input Methods
| Method | Use Case | Output |
|---|---|---|
agent.start(prompt) | Interactive terminal use | Verbose with streaming |
agent.chat(prompt) | Scripts, APIs, production | Silent, returns string |
agent.run(prompt) | Background processing | Silent, returns string |
Guardrails
Use theguardrails parameter to validate agent outputs before returning:
Function-based Guardrail
LLM-based Guardrail
Guardrail Configuration Options
| Option | Type | Description |
|---|---|---|
validator | Callable | Function: (output) -> (bool, result) |
llm_validator | str | LLM prompt for validation |
max_retries | int | Max retry attempts (default: 3) |
on_fail | str | Action on failure: "retry", "error", "return" |
Structured Output Validation
Use Pydantic models to validate and structure agent outputs via thechat() method:
Input Sanitization
Sanitize user input before processing:Advanced Topics
Rate Limiting
Rate Limiting
Prevent abuse with rate limiting:
Streamlit Integration
Streamlit Integration
Gradio Integration
Gradio Integration
Environment Variables
Environment Variables
Securely handle API keys:
Best Practices
Validate All Input
Never trust user input - validate type, format, and content
Use Guardrails
Add
guardrails= for output validation and safetySanitize for Context
Different contexts need different sanitization (HTML, SQL, shell)
Rate Limit
Prevent abuse with request limits per user
API Reference
Agent Input Methods
| Method | Description | Use Case |
|---|---|---|
start(prompt) | Interactive with verbose output | Terminal, debugging |
chat(prompt) | Silent, returns string | APIs, scripts |
run(prompt) | Silent, production mode | Background jobs |
Guardrails Parameter
| Value | Description |
|---|---|
Callable | Function: (output) -> (bool, result) |
GuardrailConfig | Full configuration with retries |
str | Preset name (e.g., "strict") |

