Agents
The Agent class is the central orchestrator in Egregore, tying together context management, provider communication, hooks, scaffolds, and workflows. Think of it as the “brain” that coordinates all the framework’s systems.What is an Agent?
An Agent represents a single AI assistant instance with:- Context tree - Maintains conversation memory and state
- Provider - Communicates with AI models (OpenAI, Anthropic, etc.)
- Hooks - Lifecycle event handlers for observability
- Scaffolds - Persistent memory and capabilities
- State system - Formal IPC for scaffold communication
- History - Snapshot-based historical access
Agents are stateful and maintain memory across interactions. Each call updates the context tree automatically.
Creating an Agent
Basic Agent
The simplest agent requires only a provider:With System Prompt
Add instructions that guide the agent’s behavior:With Configuration
Customize model parameters:Agent Lifecycle
Interaction Flow
Understanding what happens during an agent call:Automatic Context Management
Agents maintain conversation history automatically:Core Agent Methods
call() - Synchronous Interaction
Send a message and get a complete response:
acall() - Async Interaction
Async version for concurrent operations:
stream() - Streaming Response
Get real-time token-by-token responses:
events() - Event Streaming
Monitor agent activity with fine-grained event types:
Learn More
Complete guide to event streaming and event types
Agent Properties
Context Access
Direct access to the context tree:Provider Access
Interact with the underlying provider:History Access
Access historical snapshots:Hooks Access
Register lifecycle hooks:Learn More
Complete hook system documentation
Scaffolds Access
Manage agent capabilities:Thread Access
Access message formatting:Usage Tracking
Monitor token consumption:State System
Formal scaffold IPC:Learn More
Scaffold IPC and state management
Agent Configuration
Model Parameters
Configure provider-specific parameters:Provider Switching
Change providers at runtime:System Prompt Updates
Modify behavior dynamically:Tools Integration
Adding Tools
Tools extend agent capabilities:Tool Execution Loop
Agents automatically handle tool calls:Learn More
Complete tool system documentation
Scaffolds Integration
Built-in Scaffolds
Agents come with powerful built-in scaffolds:Custom Scaffolds
Add custom persistent memory:Learn More
Complete scaffold system documentation
Workflow Integration
Agents as Workflow Nodes
Agents integrate seamlessly with workflows:__call__() for workflow compatibility.
Learn More
Complete workflow system documentation
Best Practices
Use descriptive system prompts
Use descriptive system prompts
Clear instructions lead to better behavior:
Leverage scaffolds for persistence
Leverage scaffolds for persistence
Use scaffolds instead of manually managing state:
Use streaming for long responses
Use streaming for long responses
Provide better UX with streaming:
Monitor usage for cost control
Monitor usage for cost control
Track token consumption:
Use hooks for observability
Use hooks for observability
Add logging and monitoring without modifying core logic:
Common Patterns
Multi-Turn Conversation
Context-Aware Responses
Tool-Augmented Agent
Snapshot-Based Debugging
Agent State and Lifecycle
Agent ID
Each agent has a unique identifier:Agent Persistence
Agents are in-memory by default, but context can be serialized:What’s Next?
Context Management
Deep dive into context operations and lifecycle
Messaging System
Understand ProviderThread and ContentBlocks
Hooks
Lifecycle hooks for observability
Scaffolds
Persistent memory and capabilities
Tools
Extend agent capabilities with tools
Workflows
Orchestrate multi-agent systems

