7.2 KiB
Actor Configuration API Reference
Overview
CleverAgents uses an actor-first architecture where all AI interactions are performed through actors. Actors encapsulate provider, model, and configuration details into a single reusable entity.
Actor Configuration Format
Actor configurations use YAML or JSON format and must conform to the v2 schema. No alternative schemas or extensions are supported.
Basic Structure
# Minimal actor configuration
provider: openai
model: gpt-4
# Extended configuration with options
provider: anthropic
model: claude-3-opus
options:
temperature: 0.7
max_tokens: 4000
# Graph-based actor with tools
graph: ToolAgentGraph
provider: openai
model: gpt-4
tools:
- name: code_search
description: Search codebase for patterns
- name: file_reader
description: Read file contents
options:
temperature: 0.5
Configuration Fields
Core Fields
provider (required)
- Type:
string - Description: The AI provider to use
- Valid Values:
openai,anthropic,google,azure,groq,cohere,together,gemini,openrouter,mock - Example:
provider: openai
model (required)
- Type:
string - Description: The specific model from the provider
- Examples:
- OpenAI:
gpt-4,gpt-3.5-turbo - Anthropic:
claude-3-opus,claude-3-sonnet - Google:
gemini-pro,gemini-pro-vision
- OpenAI:
graph (optional)
- Type:
string - Description: The LangGraph workflow to use
- Default:
BasicChatGraph - Available Graphs:
BasicChatGraph- Simple chat completionPlanGenerationGraph- Multi-step plan generationContextAnalysisAgent- Code analysis workflowAutoDebugGraph- Error detection and fixingToolAgentGraph- Tool-calling agent
options (optional)
- Type:
object - Description: Provider-specific configuration options
- Common Options:
options: temperature: 0.7 # Creativity (0.0-1.0) max_tokens: 4000 # Maximum response length top_p: 0.9 # Nucleus sampling frequency_penalty: 0.0 # Reduce repetition presence_penalty: 0.0 # Encourage new topics stop: ["```", "\n\n"] # Stop sequences
Advanced Fields
tools (optional)
- Type:
array - Description: Tools available to the actor (requires compatible graph)
- Structure:
tools: - name: tool_name description: What the tool does parameters: param1: string param2: number
context (optional)
- Type:
object - Description: Initial context variables injected at runtime
- Example:
context: project_type: web_app language: python framework: fastapi
unsafe (optional)
- Type:
boolean - Description: Explicitly mark configuration as unsafe
- Default: Auto-detected based on content
- Note: Unsafe actors require
--unsafeflag when adding
Graph Descriptors
Graph descriptors are automatically generated from the configuration and describe the actor's capabilities:
{
"type": "PlanGenerationGraph",
"capabilities": ["streaming", "retry", "validation"],
"nodes": ["analyze", "generate", "validate"],
"edges": ["conditional", "retry"],
"requires_context": true
}
Capability Flags
streaming- Supports real-time output streamingretry- Has built-in retry logicvalidation- Validates outputs before returningtools- Can use external toolsmemory- Maintains conversation historycontext- Requires or uses context
Unsafe Detection Rules
Configurations are analyzed for potentially unsafe operations:
Automatically Detected as Unsafe
-
Shell/System Access
tools: - name: shell_execute description: Execute shell commands -
File System Writes
tools: - name: file_write description: Write to filesystem parameters: path: string content: string -
Network Access
tools: - name: http_request description: Make HTTP requests -
Code Execution
graph: CodeExecutionGraph options: allow_exec: true
Marking as Safe
If auto-detection incorrectly flags a configuration:
# Override auto-detection
unsafe: false
provider: openai
model: gpt-4
# ... rest of config
Environment Variable Interpolation
Actor configurations support environment variable interpolation:
provider: openai
model: ${MODEL_NAME:-gpt-4}
options:
api_key: ${OPENAI_API_KEY}
temperature: ${TEMPERATURE:-0.7}
max_tokens: ${MAX_TOKENS:-4000}
Interpolation Syntax
${VAR}- Use environment variable VAR${VAR:-default}- Use VAR or default value if not set${VAR:?error message}- Error if VAR not set
Provider/Model Mapping
Actor configurations map to provider implementations:
OpenAI Example
provider: openai
model: gpt-4
Maps to:
- Provider class:
OpenAIProvider - Model identifier:
gpt-4 - API endpoint:
https://api.openai.com/v1
Custom Endpoints
provider: openai
model: gpt-4
options:
base_url: http://localhost:8080/v1
api_key: local-key
Configuration Hash Calculation
The configuration hash is a SHA-256 digest of the canonical JSON representation:
- Parse YAML/JSON to object
- Remove comments and formatting
- Sort keys alphabetically
- Serialize to canonical JSON
- Calculate SHA-256 hash
Example:
config_hash = hashlib.sha256(
json.dumps(config, sort_keys=True).encode()
).hexdigest()
Usage in Commands
Creating Custom Actors
# From configuration file
agents actor add --name assistant --config ./assistant.yaml
# Results in actor: local/assistant
Using Actors
# Use specific actor
agents tell "refactor this function" --actor local/assistant
# Use with options override
agents build --actor openai/gpt-4 --option temperature=0.2
Built-in Actor Names
Built-in actors follow the pattern <provider>/<model>:
openai/gpt-4openai/gpt-3.5-turboanthropic/claude-3-opusgoogle/gemini-promock/test-model
Error Handling
Common Configuration Errors
-
Missing Required Fields
ERROR: Configuration missing required field 'provider' -
Invalid Provider/Model
ERROR: Unknown provider 'invalid' -
Unsafe Without Flag
ERROR: Configuration appears unsafe. Add --unsafe flag to confirm. -
Invalid YAML/JSON
ERROR: Failed to parse configuration: expected ':', got '}'
Best Practices
-
Use Descriptive Names
agents actor add --name code-reviewer --config ./reviewer.yaml -
Set Appropriate Options
# For code generation options: temperature: 0.2 # Lower for consistency max_tokens: 8000 # Higher for complete code -
Document Custom Actors
# Code review assistant optimized for Python provider: openai model: gpt-4 context: purpose: code_review language: python -
Version Control Configurations
- Store actor configs in
./actors/directory - Track changes in git
- Use meaningful commit messages
- Store actor configs in