任务管理代理

一个通过CLI和HTTP API管理Laravel任务的代理,支持RAG(PDF问答)和实时上下文切换聊天演示。

  • by alchiebinan21
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 alchiebinan21/task_management_agent

使用说明

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)

  1. Clone and run task_management_app (Laravel)
  2. Clone task_management_mcp and configure paths in .env
  3. Start this agent: python api_server.py → http://127.0.0.1:8001
  4. Clone and run task_management_ui → http://localhost:3000

Full step-by-step instructions: see the task_management_ui README.

Setup

  1. 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
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. 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)

  1. Get a Gemini API key from https://makersuite.google.com/app/apikey
  2. Add to your .env file:
    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)

  1. Get a Groq API key from https://console.groq.com/keys
  2. Add to your .env file:
    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)

  1. Get an OpenAI API key from https://platform.openai.com/api-keys
  2. Add to your .env file:
    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 info
  • GET /health - Health check
  • GET /tasks - List all tasks
  • GET /tasks/{task_id} - Get a specific task
  • POST /tasks - Create a new task
  • PUT /tasks/{task_id} - Update a task
  • DELETE /tasks/{task_id} - Delete a task
  • POST /chat - Natural language task operations (LLM-powered)
  • POST /rag/upload - Index a PDF for RAG
  • GET /rag/status - RAG index status
  • POST /rag/chat - Ask questions about indexed PDF
  • DELETE /rag/clear - Clear RAG index
  • GET /context/presets - Context demo presets
  • POST /context/chat - Context-switching chat (session history)
  • POST /context/switch - Switch live context without clearing history
  • GET /context/session/{session_id} - Get session state

Integration with Nuxt.js 3

When you're ready to integrate with your Nuxt.js frontend:

  1. Start the API server:

    python api_server.py
    
  2. 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'
    
  3. Make API calls from your Nuxt components:

    const { data: tasks } = await useFetch(`${API_BASE_URL}/tasks`)
    
  4. Update CORS settings in api_server.py to 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:

  1. Start the API server in one terminal:

    python api_server.py
    
  2. In another terminal, run the test script:

    ./test_api.sh
    

    Or 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/docs in your browser for interactive API documentation (Swagger UI)
  • Or use curl/Postman to test endpoints

Development

  • agent.py - CLI entry point
  • llm_agent.py - LLM-powered natural language agent
  • mcp_client.py - MCP server client connection
  • api_server.py - FastAPI HTTP server (for Nuxt.js integration)
  • test_agent.py - Automated test script for CLI agent
  • test_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