datawhalechina/hello-agents · error · HTTPException

Agent '{request.agent_id}' not found

Error message

Agent '{request.agent_id}' not found

What it means

POST /tasks returns HTTP 404 when the TaskCreateRequest body carries an agent_id that is not in registry.ids(). Unlike the /agents/{agent_id}/run route, here the invalid id comes from the JSON request body, and it is validated against the id set before the task is created.

Source

Thrown at Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py:78

@app.get("/agents")
def list_agents() -> dict:
    profiles = registry.list_profiles()
    return {"agents": profiles, "total": len(profiles)}


@app.post("/agents/{agent_id}/run", response_model=AgentResponse)
def run_agent(agent_id: str, request: AgentRequest) -> AgentResponse:
    try:
        return registry.get(agent_id).run(request)
    except KeyError:
        raise HTTPException(status_code=404, detail=f"Agent '{agent_id}' not found")


@app.post("/tasks", response_model=TaskRecord)
def create_task(request: TaskCreateRequest) -> TaskRecord:
    if request.agent_id not in set(registry.ids()):
        raise HTTPException(status_code=404, detail=f"Agent '{request.agent_id}' not found")
    return task_manager.create(request)


@app.get("/tasks")
def list_tasks() -> dict:
    tasks = task_manager.list()
    return {"tasks": tasks, "total": len(tasks)}


@app.get("/tasks/{task_id}", response_model=TaskRecord)
def get_task(task_id: str) -> TaskRecord:
    try:
        return task_manager.get(task_id)
    except KeyError:
        raise HTTPException(status_code=404, detail=f"Task '{task_id}' not found")


@app.post("/tasks/{task_id}/run", response_model=TaskRecord)

View on GitHub (pinned to 606a07d341)

Solutions

  1. GET /agents and copy the exact agent id into TaskCreateRequest.agent_id.
  2. Make the client fetch the agent list dynamically instead of hardcoding ids.
  3. If the agent should exist, fix its registration (see backend startup logs).

Example fix

# before
task = requests.post(f"{BASE}/tasks", json={"agent_id": "rss_digst", "input": {...}}).json()

# after
valid_ids = set(requests.get(f"{BASE}/agents").json()["agents"])
if payload["agent_id"] not in valid_ids:
    raise SystemExit(f"agent_id must be one of {valid_ids}")
task = requests.post(f"{BASE}/tasks", json=payload).json()
Defensive patterns

Strategy: validation

Validate before calling

valid_ids = {a["id"] for a in requests.get(f"{BASE}/agents").json()["agents"]}
if request.agent_id not in valid_ids:
    raise ValueError(f"agent_id must be one of {sorted(valid_ids)}")
resp = requests.post(f"{BASE}/tasks", json=request.model_dump())

Type guard

def is_known_agent(agent_id: str, registry_ids: set[str]) -> bool:
    return agent_id in registry_ids

Try / catch

try:
    resp = requests.post(f"{BASE}/tasks", json=payload)
    resp.raise_for_status()
except HTTPError as e:
    if e.response.status_code == 404:
        raise ValueError(f"agent {payload['agent_id']} not registered") from e
    raise

Prevention

When it happens

Trigger: Creating a task with {"agent_id": "rss_digst", ...} (typo) or an agent not registered in this backend instance; the task is never persisted — the request is rejected up front.

Common situations: Client hardcoded agent ids that drift from the backend's registry; environments (staging vs prod) registering different agents; typo'd agent names in orchestration scripts.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/fcc0c24f97eac22a. Report an issue: GitHub.