A TypeScript-based AI agent system with MCP (Model Context Protocol) support, multi-user chat capabilities, and extensive tool integration.
npm install @xalia/agentA TypeScript-based AI agent system with MCP (Model Context Protocol) support, multi-user chat capabilities, and extensive tool integration.
This agent provides two primary interfaces:
- Agent Mode: Single-user conversational AI with tool support
- Chat Mode: Multi-user chat server with shared AI agent sessions
``bash`From project root
yarn install
yarn workspaces run build
Example of running agent can be found in test script.
For a detailed explanation of the context system architecture, including how context is formed, compressed, and managed during agent execution, see:
š Context System Architecture Documentation
This document covers:
- Context window structure and composition
- System prompt fragment injection
- Automatic context compression
- Session file handling
- Transaction-based message flow
#### Agent (src/agent/)
- Agent: Main orchestrator class managing conversations, tools, and LLM interactions
- McpServerManager: Manages MCP tool servers, enables/disables tools dynamically
- SkillManager: Interfaces with SudoMCP backend to discover and connect to hosted MCP servers
- LLM Implementations:
- OpenAILLM: Standard OpenAI API integrationOpenAILLMStreaming
- : Streaming response supportDummyLLM
- : Mock implementation for testing
#### Chat System (src/chat/)
- ChatClient/runServer: WebSocket-based real-time communication
- ConversationManager: Orchestrates multi-user sessions with shared AI agent
- Database: Supabase integration for user management, sessions, and agent profiles
- ApiKeyManager: Authentication and authorization
#### CLI Tools (src/tool/)
- main.ts: Primary entry point with subcommands
- agentMain.ts: Single-user agent mode implementation
- chatMain.ts: Multi-user chat server/client implementation
Basic conversation:
`bash`
cli/agent-cli
One-shot with specific prompt:
`bash`
echo "Explain quantum computing" > prompt.txt
cli/agent-cli -1 --prompt prompt.txt
With image analysis:
`bash`
echo "Describe this image" > prompt.txt
cli/agent-cli --image photo.jpg --prompt prompt.txt
Using agent profile:
`bash`
cli/agent-cli --agent-profile agent/test_data/simplecalc_profile.json
Auto-approve tools:
`bash`
echo "Calculate 15 * 23" > prompt.txt
cli/agent-cli --approve-tools --prompt prompt.txt
Start server:
`bash`
node dist/agent/src/tool/main.js chat server --port 5003
Connect client:
`bash`
node dist/agent/src/tool/main.js chat client \
--session "project_discussion" \
--agent-profile "helpful_assistant"
Run scripted conversation:
`bash`
node dist/agent/src/tool/main.js chat client \
--session "test" \
--script conversation_script.txt
While in agent mode, use these commands:
Tool Management:
- /ls - List available MCP servers/lt
- - List current tools (enabled marked with \*)/as
- - Add and enable all tools from server/e
- - Enable specific tool/d
- - Disable specific tool
Media and Data:
- :i image.jpg - Include image with next message/wc conversation.json
- - Save conversation to file/wa profile.json
- - Save agent profile to file
General:
- /h - Show help menu/q
- - Quit
`bashLLM Configuration
LLM_URL=http://localhost:5001/v1 # LLM API endpoint
LLM_API_KEY=your_openai_key # API key for LLM
LLM_MODEL=gpt-4o # Model name
$3
Agent profiles define the AI's behavior and available tools:
`json
{
"model": "gpt-4o",
"system_prompt": "You are a helpful coding assistant.",
"mcp_settings": {
"github": ["create_issue", "list_repos"]
}
}
`Development
$3
`
src/
āāā agent/ # Core AI agent implementation
ā āāā agent.ts # Main Agent orchestrator
ā āāā mcpServerManager.ts # MCP tool management
ā āāā sudoMcpServerManager.ts # SudoMCP integration
ā āāā *LLM.ts # LLM provider implementations
āāā chat/ # Multi-user chat system
ā āāā server.ts # WebSocket chat server
ā āāā client.ts # Chat client implementation
ā āāā db.ts # Database models and queries
ā āāā conversationManager.ts # Session orchestration
āāā tool/ # CLI interfaces
ā āāā main.ts # Primary entry point
ā āāā agentMain.ts # Single-user mode
ā āāā chatMain.ts # Multi-user mode
āāā test/ # Test suites
`$3
`bash
Run test suite
yarn testTest MCP server integration (requires local backend)
yarn test -- --grep "MCP"Test database operations (requires Supabase)
yarn test -- --grep "DB"
`$3
`bash
Git commit message generation
./scripts/git_messagePR description generation
./scripts/pr_messageCode review assistance
./scripts/pr_reviewMulti-user chat testing
./scripts/test_chat
`Advanced Features
$3
Use mock responses for development:
`bash
cli/agent \
--agent-profile test_data/test_script_profile.json \
--prompt "Test prompt"
`$3
Save and restore conversation state:
`bash
Save conversation
cli/agent agent --conversation-output saved_conversation.jsonRestore conversation
cli/agent --conversation saved_conversation.json
``