使用说明
Task Agent
CLI and HTTP API agent for managing Laravel Tasks via MCP Server, plus RAG (PDF Q&A) and live context-switching chat demos.
Quick start (with Nuxt UI)
- Clone and run task_management_app (Laravel)
- Clone task_management_mcp and configure paths in
.env - Start this agent:
python api_server.py→http://127.0.0.1:8001 - Clone and run task_management_ui →
http://localhost:3000
Full step-by-step instructions: see the task_management_ui README.
Setup
-
Create virtual environment (using Python 3.10+):
python3.12 -m venv .venv # or python3.10, python3.11, etc. source .venv/bin/activate # On Windows: .venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Configure environment:
cp .env.example .env # Edit .env with your configuration
Usage
CLI Agent
The CLI agent connects to your MCP server and provides commands for task management.
List all tasks:
python agent.py list
Show a specific task:
python agent.py show <task_id>
Create a new task:
python agent.py create "Task title" --description "Task description" --status pending
Update a task:
python agent.py update <task_id> --title "New title" --status completed
Delete a task:
python agent.py delete <task_id>
LLM-Powered Natural Language Agent
The agent now supports natural language commands using multiple LLM providers. This allows you to interact with tasks using conversational language instead of structured commands.
Supported Providers:
- Google Gemini (FREE: 1,500 requests/day) - Recommended for free tier
- Groq (FREE: 6,000 tokens/minute) - Very fast, great for real-time
- OpenAI (Paid) - GPT-4o-mini and other models
Setup:
Option 1: Google Gemini (FREE - Recommended)
- Get a Gemini API key from https://makersuite.google.com/app/apikey
- Add to your
.envfile:LLM_PROVIDER=gemini GEMINI_API_KEY=your-gemini-api-key-here GEMINI_MODEL=gemini-1.5-flash # Optional, defaults to gemini-1.5-flash
Option 2: Groq (FREE - Very Fast)
- Get a Groq API key from https://console.groq.com/keys
- Add to your
.envfile:LLM_PROVIDER=groq GROQ_API_KEY=your-groq-api-key-here GROQ_MODEL=llama-3.1-8b-instant # Optional, defaults to llama-3.1-8b-instant
Option 3: OpenAI (Paid)
- Get an OpenAI API key from https://platform.openai.com/api-keys
- Add to your
.envfile:LLM_PROVIDER=openai OPENAI_API_KEY=your-openai-api-key-here OPENAI_MODEL=gpt-4o-mini # Optional, defaults to gpt-4o-mini
CLI Usage:
# List tasks (uses provider from LLM_PROVIDER env var or defaults to gemini)
python agent.py chat "show me all tasks"
python agent.py chat "what tasks do I have?"
# Use a specific provider
python agent.py chat --provider gemini "show me all tasks"
python agent.py chat --provider groq "create a task called 'Test'"
# Get a specific task
python agent.py chat "show task 5"
python agent.py chat "what is task 3?"
# Create a task
python agent.py chat "create a task called 'Buy groceries'"
python agent.py chat "add a new task 'Finish report' with status in_progress"
# Update a task
python agent.py chat "mark task 2 as completed"
python agent.py chat "update task 3 title to 'New title'"
python agent.py chat "change task 1 status to in_progress"
# Delete a task
python agent.py chat "delete task 5"
python agent.py chat "remove task 3"
API Usage:
# POST /chat endpoint (uses provider from LLM_PROVIDER env var)
curl -X POST http://127.0.0.1:8001/chat \
-H "Content-Type: application/json" \
-d '{"query": "show me all tasks"}'
# With specific provider
curl -X POST http://127.0.0.1:8001/chat \
-H "Content-Type: application/json" \
-d '{"query": "create a task called Test", "provider": "gemini"}'
# With custom model
curl -X POST http://127.0.0.1:8001/chat \
-H "Content-Type: application/json" \
-d '{"query": "show tasks", "provider": "groq", "model": "llama-3.1-70b-versatile"}'
The LLM agent interprets your natural language and automatically executes the appropriate task operations.
HTTP API Server (Future)
Start the FastAPI server:
# Make sure virtual environment is activated
source .venv/bin/activate
python3 api_server.py
# Or with uvicorn directly:
uvicorn api_server:app --host 127.0.0.1 --port 8001
The API will be available at http://127.0.0.1:8001
API Endpoints:
GET /- API infoGET /health- Health checkGET /tasks- List all tasksGET /tasks/{task_id}- Get a specific taskPOST /tasks- Create a new taskPUT /tasks/{task_id}- Update a taskDELETE /tasks/{task_id}- Delete a taskPOST /chat- Natural language task operations (LLM-powered)POST /rag/upload- Index a PDF for RAGGET /rag/status- RAG index statusPOST /rag/chat- Ask questions about indexed PDFDELETE /rag/clear- Clear RAG indexGET /context/presets- Context demo presetsPOST /context/chat- Context-switching chat (session history)POST /context/switch- Switch live context without clearing historyGET /context/session/{session_id}- Get session state
Integration with Nuxt.js 3
When you're ready to integrate with your Nuxt.js frontend:
-
Start the API server:
python api_server.py -
In your Nuxt.js app, configure the API base URL:
// nuxt.config.ts or composables/useApi.ts const API_BASE_URL = 'http://127.0.0.1:8001' -
Make API calls from your Nuxt components:
const { data: tasks } = await useFetch(`${API_BASE_URL}/tasks`) -
Update CORS settings in
api_server.pyto allow your Nuxt.js frontend domain.
Architecture
Nuxt.js UI (:3000)
↓ proxy /api/task, /api/rag
Task Agent HTTP API (FastAPI :8001)
├─ LLM chat → MCP Client → MCP Server → Laravel API
├─ RAG (PDF + Chroma + LLM)
└─ Context demo (session + live context switch)
Testing
Quick Test Script
Test the CLI Agent:
# Make sure virtual environment is activated
source .venv/bin/activate
# Run the test
python3 test_agent.py
This will test all CRUD operations:
- List tasks
- Create a task
- Get a specific task
- Update a task
- Delete a task
Test the HTTP API:
-
Start the API server in one terminal:
python api_server.py -
In another terminal, run the test script:
./test_api.shOr test manually with curl:
# Health check curl http://127.0.0.1:8001/health # List tasks curl http://127.0.0.1:8001/tasks # Create a task curl -X POST http://127.0.0.1:8001/tasks \ -H "Content-Type: application/json" \ -d '{"title": "Test Task", "description": "Testing", "status": "pending"}'
Manual Testing
CLI Commands:
# Make sure virtual environment is activated first
source .venv/bin/activate
# List all tasks
python3 agent.py list
# Create a task
python3 agent.py create "My Task" --description "Task description" --status pending
# Show a task (replace <task_id> with actual ID)
python3 agent.py show <task_id>
# Update a task
python3 agent.py update <task_id> --status completed
# Delete a task
python3 agent.py delete <task_id>
API Endpoints (with server running):
- Open
http://127.0.0.1:8001/docsin your browser for interactive API documentation (Swagger UI) - Or use curl/Postman to test endpoints
Development
agent.py- CLI entry pointllm_agent.py- LLM-powered natural language agentmcp_client.py- MCP server client connectionapi_server.py- FastAPI HTTP server (for Nuxt.js integration)test_agent.py- Automated test script for CLI agenttest_api.sh- Automated test script for HTTP API.env- Configuration file
Notes
- The agent connects to the MCP server via stdio (standard input/output)
- The MCP server must be running and configured in Cursor's
mcp.json - For production, consider adding authentication to the HTTP API layer
