The Agent Loop: Observe → Think → Act → Remember
Every agent operates in a continuous cycle:src/agent/runtime.ts:184-223
AgentRuntime Class
Source:src/agent/runtime.ts:32-350
1. Observe Phase
The agent gathers context about its current state. Implementation (src/agent/runtime.ts:227-266):
2. Think Phase
The agent sends observations to the LLM along with its strategy and available skills. Implementation (src/agent/runtime.ts:270-302):
src/agent/runtime.ts:324-349):
3. Act Phase
The agent executes the chosen skill through the SkillRegistry. Implementation (src/agent/runtime.ts:306-320):
{skill: "swap", params: {inputToken: "SOL", outputToken: "USDC", amount: 0.5}}, the SkillRegistry executes the swapSkill with those parameters.
4. Remember Phase
The agent persists the decision and outcome to its memory store. Implementation (src/agent/runtime.ts:202-222):
data/memory/{agentId}.json and injected into the next cycle’s “Think” phase.
LLM Providers
Karen supports multiple LLM providers with a unified interface. Supported Providers:- OpenAI - GPT-4o, GPT-4o-mini, GPT-3.5-turbo
- Anthropic - Claude Sonnet 4, Claude 3.5 Sonnet, Claude 3 Haiku
- xAI - Grok-3-latest
- Google - Gemini 2.0 Flash
src/agent/llm/provider.ts:28-35):
- OpenAI
- Anthropic
- Grok / Gemini
Implementation: Configuration:
src/agent/llm/openai.tsAgent Skills
Skills are the actions agents can perform. Karen includes 17 built-in skills. Skill Interface (src/agent/skills/index.ts:27-35):
Core Skills
Core Skills
check_balance- Check wallet SOL and token balancesswap- Swap tokens via Jupiter DEXtransfer- Send SOL to another addressairdrop- Request devnet SOL airdroptoken_info- Look up token metadatawait- Do nothing this cycle
src/agent/skills/index.ts:94-121 (check_balance)Token Lifecycle Skills
Token Lifecycle Skills
launch_token- Create a new SPL token with initial supplymint_supply- Mint additional tokens (requires mint authority)revoke_mint_authority- Permanently disable mintingburn_tokens- Burn (destroy) tokensclose_token_account- Close empty token accounts to reclaim rent
src/agent/skills/index.ts:311-362 (launch_token)DeFi Skills
DeFi Skills
stake_sol- Stake SOL to a validatorunstake_sol- Deactivate a stake accountwithdraw_stake- Withdraw deactivated stakelist_stakes- List all stake accountswrap_sol- Convert SOL to wSOLunwrap_sol- Convert wSOL back to SOL
src/agent/skills/index.ts:438-476 (stake_sol)SKILLS.md in the source repository or src/agent/skills/index.ts:695-726
Agent Memory
Agents persist their decision history to learn from past actions. MemoryStore Class (src/agent/memory/memory-store.ts:20-83):
data/memory/{agentId}.json):
Agent Configuration
AgentConfig Type (src/core/types.ts:136-147):
src/agent/orchestrator.ts:92-163):
Orchestrator: Managing Multiple Agents
TheOrchestrator class manages concurrent agents.
Key Methods (src/agent/orchestrator.ts:32-266):
data/agents.json
Chat Interface
Agents can respond to direct messages (used by dashboard and CLI). Implementation (src/agent/runtime.ts:140-158):
Next Steps
Architecture
Understand the full system architecture
Wallets
Learn about wallet creation and management
Security
Explore guardrails and transaction security
Skills Reference
See all 17 available agent skills