Core Services
Dexto's architecture is built around core services that handle different aspects of agent functionality. Understanding these services helps with debugging, customization, and troubleshooting.
Service Overview
Service | Purpose | Key Responsibilities |
---|---|---|
DextoAgent | Main orchestrator | Coordinates all services, handles user interactions |
MCPManager | Tool coordination | Connects to MCP servers, manages tools and resources |
ToolManager | Tool execution | Executes tools, handles confirmations, manages internal tools |
SessionManager | Conversation state | Manages chat sessions, conversation history |
StorageManager | Data persistence | Handles cache and database storage |
PromptManager | System prompts | Manages system prompt assembly and dynamic content |
AgentEventBus | Event coordination | Handles inter-service communication |
Service Relationships
DextoAgent
Main orchestrator that coordinates all other services.
Key Methods
start()
- Initialize all servicesrun(prompt, tools?, sessionId?)
- Execute user promptswitchLLM(updates)
- Change LLM model/providercreateSession(sessionId?)
- Create new chat sessionstop()
- Shutdown all services
Usage Example
const agent = new DextoAgent(config);
await agent.start();
// Run a task
const response = await agent.run("List files in current directory");
// Switch models
await agent.switchLLM({ model: "claude-4-sonnet-20250514" });
await agent.stop();
MCPManager
Tool coordination service that connects to Model Context Protocol servers.
Key Methods
connectServer(name, config)
- Connect to MCP serverdisconnectServer(name)
- Disconnect servergetAllTools()
- Get all available toolsexecuteTool(name, params)
- Execute specific tool
Server Types
- stdio - Command-line programs
- http - HTTP REST endpoints
- sse - Server-sent events
Usage Example
// Connect filesystem tools
await agent.mcpManager.connectServer('filesystem', {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '.']
});
// Get available tools
const tools = await agent.mcpManager.getAllTools();
ToolManager
Tool execution service that handles tool calls and confirmations.
Key Methods
getToolStats()
- Get tool counts (MCP + internal)getAllTools()
- Get all available toolsexecuteTool(call)
- Execute tool with confirmation
Tool Confirmation
Controls when users are prompted to approve tool execution:
- auto - Smart approval based on tool risk
- always - Always ask for confirmation
- never - Never ask (auto-approve)
Usage Example
// Get tool statistics
const stats = await agent.toolManager.getToolStats();
console.log(`${stats.total} tools: ${stats.mcp} MCP, ${stats.internal} internal`);
SessionManager
Conversation state management for persistent chat sessions.
Key Methods
createSession(sessionId?)
- Create new sessionloadSession(sessionId)
- Load existing sessionlistSessions()
- List all sessionsdeleteSession(sessionId)
- Delete sessiongetSessionHistory(sessionId)
- Get conversation history
Session Features
- Persistent conversation history
- Session metadata (creation time, last activity)
- Cross-session search capabilities
- Export/import functionality
Usage Example
// Create and switch to new session
const sessionId = await agent.createSession('work-session');
// List all sessions
const sessions = await agent.listSessions();
// Get conversation history
const history = await agent.getSessionHistory('work-session');
StorageManager
Data persistence using two-tier architecture.
Storage Tiers
- Cache - Fast, ephemeral (Redis or in-memory)
- Database - Persistent, reliable (PostgreSQL, SQLite)
Backends
Backend | Use Case | Configuration |
---|---|---|
in-memory | Development, testing | No config needed |
sqlite | Single instance, persistence | path: ./data/dexto.db |
postgres | Production, scaling | connectionString: $POSTGRES_URL |
redis | Fast caching | url: $REDIS_URL |
Usage Pattern
storage:
cache:
type: redis # Fast access
url: $REDIS_URL
database:
type: postgres # Persistent storage
connectionString: $POSTGRES_CONNECTION_STRING
PromptManager
System prompt assembly from multiple contributors.
Contributor Types
- static - Fixed text content
- dynamic - Generated content (e.g., current date/time)
- file - Content from files (.md, .txt)
Priority System
Lower numbers execute first (0 = highest priority).
Usage Example
systemPrompt:
contributors:
- id: primary
type: static
priority: 0
content: "You are a helpful AI assistant..."
- id: dateTime
type: dynamic
priority: 10
source: dateTime
- id: context
type: file
priority: 5
files: ["./docs/context.md"]
AgentEventBus
Event coordination for inter-service communication.
Event Types
- thinking - AI is processing
- chunk - Streaming response chunk
- toolCall - Tool execution starting
- toolResult - Tool execution completed
- response - Final response ready
Usage Example
agent.agentEventBus.on('toolCall', (event) => {
console.log(`Executing tool: ${event.toolName}`);
});
agent.agentEventBus.on('response', (event) => {
console.log(`Response: ${event.content}`);
});
Service Initialization
Services are initialized automatically when DextoAgent.start()
is called:
- Storage - Cache and database connections
- Events - Event bus setup
- Prompts - System prompt assembly
- MCP - Server connections
- Tools - Tool discovery and validation
- Sessions - Session management ready
Debugging Services
Log Levels
# Enable debug logging
DEXTO_LOG_LEVEL=debug dexto
# Service-specific debugging
DEXTO_LOG_LEVEL=silly dexto # Most verbose
Service Health Checks
// Check MCP connections
const connectedServers = agent.mcpManager.getClients();
const failedConnections = agent.mcpManager.getFailedConnections();
// Check tool availability
const toolStats = await agent.toolManager.getToolStats();
// Check storage status
const storageHealth = agent.storageManager.getStatus();
Common Issues
- MCP connection failures - Check command paths, network access
- Storage errors - Verify database/Redis connections
- Tool execution timeouts - Increase timeout in server config
- Session persistence issues - Check database backend health
Service Configuration
Each service can be configured through the agent config:
# MCP server connections
mcpServers:
filesystem:
type: stdio
command: npx
timeout: 30000
# Storage backends
storage:
cache:
type: redis
database:
type: postgres
# Session limits
sessions:
maxSessions: 100
sessionTTL: 3600000
# Tool confirmation
toolConfirmation:
mode: auto
timeout: 30000
See Configuration Guide for complete config options.