infiniflow/ragflow · error · LookupError

Agent not found.

Error message

Agent not found.

What it means

LookupError raised by UserCanvasService.get_agent_dsl_with_release when cls.get_by_id(agent_id) returns nothing: no user_canvas row exists for that agent id. The function loads an agent's DSL (optionally its latest released version), so a missing canvas row means the agent was deleted or the id is wrong. Callers include the completion() flow when no session_id is given.

Source

Thrown at api/db/services/canvas_service.py:341

        e, c = UserCanvasService.get_by_canvas_id(canvas_id)
        if not e:
            return False

        tids = [t.tenant_id for t in UserTenantService.query(user_id=tenant_id)]
        if c["user_id"] == tenant_id:
            return True
        if c["user_id"] not in tids:
            return False
        if c["permission"] != TenantPermission.TEAM.value:
            return False
        return True

    @classmethod
    def get_agent_dsl_with_release(cls, agent_id, release_mode=False, tenant_id=None):
        e, cvs = cls.get_by_id(agent_id)
        if not e:
            raise LookupError("Agent not found.")

        if release_mode:
            released_version = UserCanvasVersionService.get_latest_released(agent_id)
            if not released_version:
                raise PermissionError("No available published version")
            dsl = released_version.dsl
        else:
            dsl = cvs.dsl

        if not isinstance(dsl, str):
            dsl = json.dumps(dsl, ensure_ascii=False)

        return cvs, dsl


async def completion(tenant_id, agent_id, session_id=None, **kwargs):
    query = kwargs.get("query", "") or kwargs.get("question", "")
    files = kwargs.get("files", [])

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Verify the agent exists for the tenant (user_canvas table / GET /api/v1/canvases) and copy the correct id.
  2. If deleted, restore or recreate the agent and update the caller's stored id.
  3. Handle the LookupError in clients with a 404-style response instead of retrying.
  4. Check you are passing agent_id, not session_id, to endpoints that expect an agent.
Defensive patterns

Strategy: try-catch

Validate before calling

exist, cvs = UserCanvasService.get_by_id(agent_id)
if not exist:
    raise ValueError(f"Agent {agent_id} not found; check the id in GET /api/v1/canvases")

Type guard

def agent_exists(agent_id: str) -> bool:
    return UserCanvasService.get_by_id(agent_id)[0]

Try / catch

try:
    cvs, dsl = UserCanvasService.get_agent_dsl_with_release(agent_id, ...)
except LookupError:
    return jsonify(error="Agent not found"), 404

Prevention

When it happens

Trigger: POSTing a completion/run request with an agent_id that doesn't exist; agent deleted between page load and run; id truncated or from another environment; releasing/running an id that was a session id by mistake.

Common situations: Stale agent picker in the UI after another user deleted the agent; API scripts with hard-coded agent ids; importing conversations without importing the canvases.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/5393e1d6e63e4a64. Report an issue: GitHub.