A Node.js mock server that simulates the OpenAI API with hardcoded responses and command execution tool calling.
- OpenAI-compatible
/v1/chat/completionsendpoint - Supports
execute_commandtool/function calling - Hardcoded command mappings based on user input keywords
- Easy to customize via JSON config
- Logging of requests and responses
npm installnpm startThe server will run on http://localhost:3333
$ export AGENT_API=https://localhost:3333
./agent
You: execute command
[Tool Call] execute_command({"command":"echo","args":["I'm naive agent, sorry."]})
[Tool Result] Command 'echo' executed successfully:
I'm naive agent, sorry.
Agent: I am a mock AI assistant. I can execute commands for you. Try asking me to execute a command!
You:The mock API matches user messages against keywords and returns predefined responses:
| Keyword | Response Type | Action |
|---|---|---|
| "execute command" | Function call | Calls execute_command (executed locally by agent) |
| "run command" | Function call | Calls execute_command (executed locally by agent) |
| "execute" | Function call | Calls execute_command (executed locally by agent) |
| "run" | Function call | Calls execute_command (executed locally by agent) |
| (anything else) | Text response | Returns default greeting message |
Standard OpenAI chat completions endpoint.
Request:
{
"model": "gpt-4-turbo-preview",
"messages": [
{"role": "user", "content": "Execute command ls"}
],
"tools": [
{
"type": "function",
"function": {
"name": "execute_command",
"description": "Execute a system command",
"parameters": {
"type": "object",
"properties": {
"command": {"type": "string"},
"args": {"type": "array", "items": {"type": "string"}}
},
"required": ["command"]
}
}
}
]
}Response (with tool call):
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1234567890,
"model": "gpt-4-turbo-preview",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_exec",
"type": "function",
"function": {
"name": "execute_command",
"arguments": "{\"command\":\"echo\",\"args\":[\"Hello from command execution!\"]}"
}
}]
},
"finish_reason": "tool_calls"
}],
"usage": {
"prompt_tokens": 50,
"completion_tokens": 20,
"total_tokens": 70
}
}Returns list of available models.
Health check endpoint.
Edit config.json to change what commands get executed for different keywords - no code changes needed!
{
"keywords": ["list files", "show files"],
"action": "function_call",
"tool_call": {
"id": "call_ls",
"function_name": "execute_command",
"arguments": {
"command": "ls",
"args": ["-la"]
}
}
}After editing config.json, restart the server to apply changes.
MIT
