Skill Architecture
Skills in Karen follow a simple but powerful pattern:- Skill Interface: Defines the contract for a skill (name, description, parameters, execute function)
- Skill Registry: Central registry that manages all available skills
- Skill Context: Provides access to wallet manager, transaction engine, and protocol adapters
- LLM Integration: Skills are automatically exposed to the LLM as function tools
The Skill Interface
Every skill must implement theSkill interface defined in src/agent/skills/index.ts:27:
Skill Context
TheSkillContext provides access to all core infrastructure (src/agent/skills/index.ts:15):
- Wallet operations: Create, sign, and manage wallets
- Transaction execution: Submit transactions with guardrail protection
- DeFi protocols: Jupiter swaps, SPL tokens, staking, and more
Creating a Custom Skill
Let’s create a custom skill that checks the current SOL price from an oracle and executes a conditional swap.Built-in Skill Examples
Karen includes 17 built-in skills. Here are some examples to learn from:Simple Skill: Check Balance
The balance skill shows how to access wallet data (src/agent/skills/index.ts:94):
Complex Skill: Jupiter Swap
The swap skill demonstrates transaction execution with guardrails (src/agent/skills/index.ts:123):
Parameter Validation
Theparameters field uses JSON Schema format. The LLM uses this schema to understand how to call your skill:
Always provide clear descriptions for each parameter. The LLM relies on these descriptions to understand how to use your skill correctly.
Error Handling
Return error messages as strings. The SkillRegistry automatically catches exceptions (src/agent/skills/index.ts:82):
Testing Your Skill
Test skills by creating a test agent with a targeted strategy:Advanced: Dynamic Skill Loading
For production use, you can create a dynamic skill loader:Best Practices
- Clear Naming: Use descriptive skill names that indicate what the skill does
- Detailed Descriptions: Write comprehensive descriptions for both the skill and its parameters
- Input Validation: Always validate and sanitize user inputs
- Error Messages: Return helpful error messages that explain what went wrong
- Return Format: Return human-readable strings that the LLM can understand
- Transaction Safety: Use the
transactionEngineto ensure guardrails are applied - Idempotency: Design skills to be safely retried if needed
Next Steps
- Learn about Configuration to adjust guardrails and LLM settings
- Monitor your agents using the Dashboard
- Review the API Reference for external integration