@xalia/agent 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -51
- package/package.json +1 -1
- package/scripts/setup_chat +85 -0
- package/scripts/shutdown_chat_server +39 -0
- package/scripts/start_chat_server +24 -0
- package/scripts/test_chat +31 -5
package/README.md
CHANGED
@@ -1,95 +1,232 @@
|
|
1
|
-
#
|
1
|
+
# Xalia Agent
|
2
2
|
|
3
|
-
|
3
|
+
A TypeScript-based AI agent system with MCP (Model Context Protocol) support, multi-user chat capabilities, and extensive tool integration.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
This agent provides two primary interfaces:
|
8
|
+
- **Agent Mode**: Single-user conversational AI with tool support
|
9
|
+
- **Chat Mode**: Multi-user chat server with shared AI agent sessions
|
10
|
+
|
11
|
+
## Quick Start
|
12
|
+
|
13
|
+
### Setup
|
14
|
+
|
15
|
+
```bash
|
16
|
+
# From project root
|
17
|
+
yarn install
|
8
18
|
yarn workspaces run build
|
9
19
|
```
|
10
20
|
|
11
|
-
|
21
|
+
### Basic Usage
|
22
|
+
|
23
|
+
Example of running agent can be found in [test script](../mcppro/scripts/test_script).
|
24
|
+
|
25
|
+
## Architecture
|
26
|
+
|
27
|
+
### Core Components
|
28
|
+
|
29
|
+
#### Agent (`src/agent/`)
|
30
|
+
- **`Agent`**: Main orchestrator class managing conversations, tools, and LLM interactions
|
31
|
+
- **`McpServerManager`**: Manages MCP tool servers, enables/disables tools dynamically
|
32
|
+
- **`SkillManager`**: Interfaces with SudoMCP backend to discover and connect to hosted MCP servers
|
33
|
+
- **LLM Implementations**:
|
34
|
+
- `OpenAILLM`: Standard OpenAI API integration
|
35
|
+
- `OpenAILLMStreaming`: Streaming response support
|
36
|
+
- `DummyLLM`: Mock implementation for testing
|
37
|
+
|
38
|
+
#### Chat System (`src/chat/`)
|
39
|
+
- **`ChatClient`/`runServer`**: WebSocket-based real-time communication
|
40
|
+
- **`ConversationManager`**: Orchestrates multi-user sessions with shared AI agent
|
41
|
+
- **`Database`**: Supabase integration for user management, sessions, and agent profiles
|
42
|
+
- **`ApiKeyManager`**: Authentication and authorization
|
12
43
|
|
13
|
-
|
44
|
+
#### CLI Tools (`src/tool/`)
|
45
|
+
- **`main.ts`**: Primary entry point with subcommands
|
46
|
+
- **`agentMain.ts`**: Single-user agent mode implementation
|
47
|
+
- **`chatMain.ts`**: Multi-user chat server/client implementation
|
14
48
|
|
15
|
-
|
49
|
+
## Usage Examples
|
16
50
|
|
17
|
-
|
18
|
-
|
51
|
+
### Agent Mode
|
52
|
+
|
53
|
+
**Basic conversation:**
|
54
|
+
```bash
|
55
|
+
cli/agent-cli
|
19
56
|
```
|
20
57
|
|
21
|
-
|
58
|
+
**One-shot with specific prompt:**
|
59
|
+
```bash
|
60
|
+
echo "Explain quantum computing" > prompt.txt
|
61
|
+
cli/agent-cli -1 --prompt prompt.txt
|
62
|
+
```
|
22
63
|
|
23
|
-
|
24
|
-
|
64
|
+
**With image analysis:**
|
65
|
+
```bash
|
66
|
+
echo "Describe this image" > prompt.txt
|
67
|
+
cli/agent-cli --image photo.jpg --prompt prompt.txt
|
25
68
|
```
|
26
69
|
|
27
|
-
|
70
|
+
**Using agent profile:**
|
71
|
+
```bash
|
72
|
+
cli/agent-cli --agent-profile agent/test_data/simplecalc_profile.json
|
73
|
+
```
|
28
74
|
|
29
|
-
|
75
|
+
**Auto-approve tools:**
|
76
|
+
```bash
|
77
|
+
echo "Calculate 15 * 23" > prompt.txt
|
78
|
+
cli/agent-cli --approve-tools --prompt prompt.txt
|
79
|
+
```
|
30
80
|
|
31
|
-
|
81
|
+
### Chat Mode
|
32
82
|
|
33
|
-
|
83
|
+
**Start server:**
|
84
|
+
```bash
|
85
|
+
node dist/agent/src/tool/main.js chat server --port 5003
|
86
|
+
```
|
34
87
|
|
35
|
-
|
88
|
+
**Connect client:**
|
89
|
+
```bash
|
90
|
+
node dist/agent/src/tool/main.js chat client \
|
91
|
+
--session "project_discussion" \
|
92
|
+
--agent-profile "helpful_assistant"
|
93
|
+
```
|
36
94
|
|
37
|
-
|
95
|
+
**Run scripted conversation:**
|
96
|
+
```bash
|
97
|
+
node dist/agent/src/tool/main.js chat client \
|
98
|
+
--session "test" \
|
99
|
+
--script conversation_script.txt
|
100
|
+
```
|
38
101
|
|
39
|
-
|
102
|
+
### Interactive Commands (Agent Mode)
|
40
103
|
|
41
|
-
|
104
|
+
While in agent mode, use these commands:
|
42
105
|
|
43
|
-
|
106
|
+
**Tool Management:**
|
107
|
+
- `/ls` - List available MCP servers
|
108
|
+
- `/lt` - List current tools (enabled marked with *)
|
109
|
+
- `/as <server>` - Add and enable all tools from server
|
110
|
+
- `/e <server> <tool>` - Enable specific tool
|
111
|
+
- `/d <server> <tool>` - Disable specific tool
|
44
112
|
|
45
|
-
|
113
|
+
**Media and Data:**
|
114
|
+
- `:i image.jpg` - Include image with next message
|
115
|
+
- `/wc conversation.json` - Save conversation to file
|
116
|
+
- `/wa profile.json` - Save agent profile to file
|
46
117
|
|
47
|
-
|
118
|
+
**General:**
|
119
|
+
- `/h` - Show help menu
|
120
|
+
- `/q` - Quit
|
48
121
|
|
49
|
-
|
122
|
+
## Configuration
|
50
123
|
|
51
|
-
|
124
|
+
### Environment Variables
|
52
125
|
|
53
|
-
|
54
|
-
|
55
|
-
|
126
|
+
```bash
|
127
|
+
# LLM Configuration
|
128
|
+
LLM_URL=http://localhost:5001/v1 # LLM API endpoint
|
129
|
+
LLM_API_KEY=your_openai_key # API key for LLM
|
130
|
+
LLM_MODEL=gpt-4o # Model name
|
56
131
|
|
57
|
-
|
132
|
+
# SudoMCP Integration
|
133
|
+
XMCP_URL=http://localhost:5001/ # SudoMCP backend URL
|
134
|
+
API_KEY=your_sudomcp_key # SudoMCP API key
|
58
135
|
|
59
|
-
|
60
|
-
|
61
|
-
|
136
|
+
# Database (Chat Mode)
|
137
|
+
SUPABASE_URL=http://127.0.0.1:54321 # Supabase URL
|
138
|
+
SUPABASE_KEY=your_supabase_key # Supabase service key
|
62
139
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
- list of enabled / available tools per mcp server
|
67
|
-
- exposes tools to Agent
|
140
|
+
# Chat Server
|
141
|
+
CHAT_SERVER_PORT=5003 # WebSocket server port
|
142
|
+
```
|
68
143
|
|
69
|
-
|
144
|
+
### Agent Profiles
|
70
145
|
|
71
|
-
|
146
|
+
Agent profiles define the AI's behavior and available tools:
|
72
147
|
|
148
|
+
```json
|
149
|
+
{
|
150
|
+
"model": "gpt-4o",
|
151
|
+
"system_prompt": "You are a helpful coding assistant.",
|
152
|
+
"mcp_settings": {
|
153
|
+
"github": ["create_issue", "list_repos"],
|
154
|
+
}
|
155
|
+
}
|
73
156
|
```
|
74
|
-
$ ./scripts/test_chat
|
75
|
-
```
|
76
157
|
|
77
|
-
|
158
|
+
## Development
|
159
|
+
|
160
|
+
### Project Structure
|
78
161
|
|
79
162
|
```
|
80
|
-
|
81
|
-
|
82
|
-
|
163
|
+
src/
|
164
|
+
├── agent/ # Core AI agent implementation
|
165
|
+
│ ├── agent.ts # Main Agent orchestrator
|
166
|
+
│ ├── mcpServerManager.ts # MCP tool management
|
167
|
+
│ ├── sudoMcpServerManager.ts # SudoMCP integration
|
168
|
+
│ └── *LLM.ts # LLM provider implementations
|
169
|
+
├── chat/ # Multi-user chat system
|
170
|
+
│ ├── server.ts # WebSocket chat server
|
171
|
+
│ ├── client.ts # Chat client implementation
|
172
|
+
│ ├── db.ts # Database models and queries
|
173
|
+
│ └── conversationManager.ts # Session orchestration
|
174
|
+
├── tool/ # CLI interfaces
|
175
|
+
│ ├── main.ts # Primary entry point
|
176
|
+
│ ├── agentMain.ts # Single-user mode
|
177
|
+
│ └── chatMain.ts # Multi-user mode
|
178
|
+
└── test/ # Test suites
|
83
179
|
```
|
84
180
|
|
85
|
-
|
181
|
+
### Testing
|
182
|
+
|
183
|
+
```bash
|
184
|
+
# Run test suite
|
185
|
+
yarn test
|
186
|
+
|
187
|
+
# Test MCP server integration (requires local backend)
|
188
|
+
yarn test -- --grep "MCP"
|
86
189
|
|
87
|
-
|
190
|
+
# Test database operations (requires Supabase)
|
191
|
+
yarn test -- --grep "DB"
|
88
192
|
```
|
89
|
-
|
193
|
+
|
194
|
+
### Utility Scripts
|
195
|
+
|
196
|
+
```bash
|
197
|
+
# Git commit message generation
|
198
|
+
./scripts/git_message
|
199
|
+
|
200
|
+
# PR description generation
|
201
|
+
./scripts/pr_message
|
202
|
+
|
203
|
+
# Code review assistance
|
204
|
+
./scripts/pr_review
|
205
|
+
|
206
|
+
# Multi-user chat testing
|
207
|
+
./scripts/test_chat
|
90
208
|
```
|
91
209
|
|
92
|
-
|
210
|
+
## Advanced Features
|
211
|
+
|
212
|
+
### Dummy LLM for Testing
|
213
|
+
|
214
|
+
Use mock responses for development:
|
215
|
+
|
216
|
+
```bash
|
217
|
+
cli/agent \
|
218
|
+
--agent-profile test_data/test_script_profile.json \
|
219
|
+
--prompt "Test prompt"
|
93
220
|
```
|
94
|
-
|
221
|
+
|
222
|
+
### Conversation Restoration
|
223
|
+
|
224
|
+
Save and restore conversation state:
|
225
|
+
|
226
|
+
```bash
|
227
|
+
# Save conversation
|
228
|
+
cli/agent agent --conversation-output saved_conversation.json
|
229
|
+
|
230
|
+
# Restore conversation
|
231
|
+
cli/agent --conversation saved_conversation.json
|
95
232
|
```
|
package/package.json
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# Setup script for chat testing
|
4
|
+
# Handles backend/database setup, building, user creation, and profile setup
|
5
|
+
|
6
|
+
. ../mcppro/env/bin/activate
|
7
|
+
|
8
|
+
set -x
|
9
|
+
set -e
|
10
|
+
|
11
|
+
function stop_mcppro_server() {
|
12
|
+
pushd ../mcppro
|
13
|
+
if [ -e sudomcp.pid ] ; then
|
14
|
+
kill `cat sudomcp.pid` || echo -n
|
15
|
+
rm sudomcp.pid
|
16
|
+
fi
|
17
|
+
popd
|
18
|
+
}
|
19
|
+
|
20
|
+
# Setup mcppro backend and database
|
21
|
+
if [ -z ${NO_START} ] ; then
|
22
|
+
echo "Setting up mcppro backend and database..."
|
23
|
+
pushd ../mcppro
|
24
|
+
make supabase-up
|
25
|
+
stop_mcppro_server
|
26
|
+
make start-dev > server.log 2>&1 &
|
27
|
+
sleep 5
|
28
|
+
popd
|
29
|
+
fi
|
30
|
+
|
31
|
+
# Build agent
|
32
|
+
echo "Building agent..."
|
33
|
+
yarn
|
34
|
+
yarn build
|
35
|
+
agent=`realpath dist/agent/src/tool/main.js`
|
36
|
+
|
37
|
+
# Build client
|
38
|
+
echo "Building client..."
|
39
|
+
pushd ../client
|
40
|
+
yarn
|
41
|
+
yarn build
|
42
|
+
popd
|
43
|
+
|
44
|
+
client=`realpath ../client/dist/src/tool/main.js`
|
45
|
+
|
46
|
+
mkdir -p _test_chat
|
47
|
+
pushd _test_chat
|
48
|
+
|
49
|
+
# Create admin secret
|
50
|
+
echo "Creating admin secret..."
|
51
|
+
echo "XMCP_ADMIN_SECRET=admin_secret" > .env
|
52
|
+
|
53
|
+
# Create 2 users and give them api keys
|
54
|
+
echo "Creating users and API keys..."
|
55
|
+
|
56
|
+
${client} user get chatuser0 || \
|
57
|
+
mcppro dev add-user chatuser0 chatuser0@users.com "Europe/London"
|
58
|
+
${client} user get chatuser1 || \
|
59
|
+
mcppro dev add-user chatuser1 chatuser1@users.com "UTC"
|
60
|
+
|
61
|
+
apikey0=`${client} admin get-api-keys chatuser0 | jq -r .default.api_key`
|
62
|
+
if [ "null" == "${apikey0}" ] ; then
|
63
|
+
apikey0=`${client} admin create-api-key chatuser0 default [] | jq -r .api_key`
|
64
|
+
fi
|
65
|
+
apikey1=`${client} admin get-api-keys chatuser1 | jq -r .default.api_key`
|
66
|
+
if [ "null" == "${apikey1}" ] ; then
|
67
|
+
apikey1=`${client} admin create-api-key chatuser1 default [] | jq -r .api_key`
|
68
|
+
fi
|
69
|
+
|
70
|
+
echo "${apikey0}" > chatuser0.apikey
|
71
|
+
echo "${apikey1}" > chatuser1.apikey
|
72
|
+
|
73
|
+
# User 0 creates an agent profile
|
74
|
+
echo "Creating agent profile..."
|
75
|
+
|
76
|
+
echo '{"system_prompt":"You are a helpful agent talking to multiple users. Users put their name at the beginning of their messages, e.g. `chatuser1: <message>`.","mcp_settings":{"duckduckgo-search":[]}}' > profile0.json
|
77
|
+
${client} config --force --dev --api-key ${apikey0}
|
78
|
+
${client} agent-profile set profile0 --profile profile0.json
|
79
|
+
|
80
|
+
popd
|
81
|
+
|
82
|
+
|
83
|
+
echo "================================"
|
84
|
+
echo "== CHAT SETUP COMPLETED =="
|
85
|
+
echo "================================"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# Shutdown script for chat testing
|
4
|
+
# Stops chat server and MCP server
|
5
|
+
|
6
|
+
set -x
|
7
|
+
set -e
|
8
|
+
|
9
|
+
function stop_chat_server() {
|
10
|
+
echo "Stopping chat server..."
|
11
|
+
if [ -e chat.pid ] ; then
|
12
|
+
kill `cat chat.pid` || echo "Chat server was not running or already stopped"
|
13
|
+
rm chat.pid
|
14
|
+
else
|
15
|
+
echo "No chat.pid file found - chat server may not be running"
|
16
|
+
fi
|
17
|
+
}
|
18
|
+
|
19
|
+
function stop_mcppro_server() {
|
20
|
+
echo "Stopping MCP server..."
|
21
|
+
pushd ../mcppro
|
22
|
+
if [ -e sudomcp.pid ] ; then
|
23
|
+
kill `cat sudomcp.pid` || echo "MCP server was not running or already stopped"
|
24
|
+
rm sudomcp.pid
|
25
|
+
else
|
26
|
+
echo "No sudomcp.pid file found - MCP server may not be running"
|
27
|
+
fi
|
28
|
+
popd
|
29
|
+
}
|
30
|
+
|
31
|
+
# Stop chat server
|
32
|
+
stop_chat_server
|
33
|
+
|
34
|
+
# Stop MCP server
|
35
|
+
stop_mcppro_server
|
36
|
+
|
37
|
+
echo "=========================="
|
38
|
+
echo "== SHUTDOWN COMPLETE =="
|
39
|
+
echo "=========================="
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
agent=`realpath dist/agent/src/tool/main.js`
|
4
|
+
|
5
|
+
function stop_chat_server() {
|
6
|
+
echo "Stopping any existing chat server..."
|
7
|
+
if [ -e chat.pid ] ; then
|
8
|
+
kill `cat chat.pid` || echo "Chat server was not running or already stopped"
|
9
|
+
else
|
10
|
+
echo "No existing chat server found"
|
11
|
+
fi
|
12
|
+
}
|
13
|
+
|
14
|
+
# Stop any existing chat server
|
15
|
+
stop_chat_server
|
16
|
+
|
17
|
+
echo "Starting chat server..."
|
18
|
+
echo "Output will be logged to: chat_server.log"
|
19
|
+
echo "Press Ctrl+C to stop the server"
|
20
|
+
echo "================================"
|
21
|
+
|
22
|
+
# Start chat server with logging to file and console
|
23
|
+
# Using tee to duplicate output to both file and terminal
|
24
|
+
LOG_LEVEL=debug ${agent} chat server --pid-file chat.pid 2>&1 | tee chat_server.log
|
package/scripts/test_chat
CHANGED
@@ -1,25 +1,48 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
# Assumes backend and DB are already running
|
4
|
-
|
5
3
|
. ../mcppro/env/bin/activate
|
6
4
|
|
7
5
|
set -x
|
8
6
|
set -e
|
9
7
|
|
8
|
+
function stop_mcppro_server() {
|
9
|
+
pushd ../mcppro
|
10
|
+
if [ -e sudomcp.pid ] ; then
|
11
|
+
kill `cat sudomcp.pid` || echo -n
|
12
|
+
fi
|
13
|
+
popd
|
14
|
+
}
|
10
15
|
|
16
|
+
if [ -z ${NO_START} ] ; then
|
17
|
+
# Start backend services from mcppro directory
|
18
|
+
pushd ../mcppro
|
19
|
+
make supabase-up
|
20
|
+
stop_mcppro_server
|
21
|
+
make start-dev > server.log 2>&1 &
|
22
|
+
sleep 5
|
23
|
+
popd
|
24
|
+
fi
|
25
|
+
|
26
|
+
# build agent
|
11
27
|
yarn
|
12
28
|
yarn build
|
13
29
|
agent=`realpath dist/agent/src/tool/main.js`
|
30
|
+
|
31
|
+
# build client
|
32
|
+
pushd ../client
|
33
|
+
yarn
|
34
|
+
yarn build
|
35
|
+
popd
|
36
|
+
|
14
37
|
client=`realpath ../client/dist/src/tool/main.js`
|
15
38
|
|
16
|
-
function
|
39
|
+
function stop_chat_server() {
|
17
40
|
if [ -e chat.pid ] ; then
|
18
41
|
kill `cat chat.pid` || echo -n
|
19
42
|
fi
|
20
43
|
}
|
21
44
|
|
22
|
-
|
45
|
+
stop_chat_server
|
23
46
|
|
24
47
|
LOG_LEVEL=debug ${agent} chat server --pid-file chat.pid > chat_server.log 2>&1 &
|
25
48
|
sleep 1
|
@@ -74,7 +97,10 @@ pushd _test_chat
|
|
74
97
|
|
75
98
|
popd
|
76
99
|
|
77
|
-
|
100
|
+
stop_chat_server
|
101
|
+
|
102
|
+
# Stop backend services if we started them
|
103
|
+
[ -z ${NO_START} ] && stop_mcppro_server
|
78
104
|
|
79
105
|
set +e
|
80
106
|
set +x
|