Skip to content

Tutorial: Build an Agent Service

This tutorial builds a small Redis-backed agent service with a worker and a REST API.

Prerequisites

  • Python 3.11+
  • Redis

Setup

mkdir research-agent
cd research-agent
python -m venv .venv
source .venv/bin/activate
pip install "redis-agent-kit[api,cli]"
docker run -d -p 6379:6379 --name redis redis:8

Define the Agent

Create app.py:

from redis_agent_kit import AgentCard, AgentKit, EmitterMiddleware, Skill, TaskContext
from redis_agent_kit.api import create_app


async def research_agent(ctx: TaskContext) -> dict:
    await ctx.emitter.emit("Researching...")
    return {"answer": f"Research results for: {ctx.message}"}


kit = AgentKit(
    "redis://localhost:6379",
    agent_callable=research_agent,
    middleware=[EmitterMiddleware(start_message="Starting research...")],
    queue_name="research",
)

tasks = [kit.worker_task]

agent_card = AgentCard(
    name="Research Agent",
    description="Researches topics",
    url="http://localhost:8000",
    skills=[Skill(id="research", name="Research", description="Research any topic")],
)

app = create_app(
    kit=kit,
    enable_a2a=True,
    agent_card=agent_card,
)

Run It

Run the worker and server in separate terminals:

rak worker --name research --tasks app:tasks
uvicorn app:app --reload

Submit a REST task:

curl -X POST http://localhost:8000/tasks \
  -H "Content-Type: application/json" \
  -d '{"message": "What is Redis?"}'

Response:

{"task_id": "01J...", "session_id": "01J...", "status": "queued", "message": "Task created and queued for processing"}

Poll the task until it completes:

curl http://localhost:8000/tasks/01J...

Try A2A Discovery

curl http://localhost:8000/.well-known/agent.json

Send an A2A message:

curl -X POST http://localhost:8000 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "message/send",
    "params": {
      "message": {
        "role": "user",
        "parts": [{"type": "text", "text": "What is Redis?"}]
      }
    },
    "id": 1
  }'

Add ACP

Add an ACP manifest and enable ACP in create_app():

from redis_agent_kit import AgentManifest

agent_manifest = AgentManifest(
    name="research-agent",
    description="Researches topics",
)

app = create_app(
    kit=kit,
    enable_a2a=True,
    enable_acp=True,
    agent_card=agent_card,
    agent_manifest=agent_manifest,
)

Create an ACP run:

curl -X POST http://localhost:8000/runs \
  -H "Content-Type: application/json" \
  -d '{
    "agent_name": "research-agent",
    "input": [
      {"role": "user", "parts": [{"type": "text", "content": "What is Redis?"}]}
    ]
  }'

Add MCP

Install the MCP extra and create mcp_server.py:

pip install "redis-agent-kit[mcp]"
from redis_agent_kit.mcp import create_server

server = create_server(redis_url="redis://localhost:6379", name="research-agent")

Run:

fastmcp run mcp_server.py

Next Steps