Score roles per search agent, and run pull into extract, embed and score

embed stores one vector per open role; score rates every open role for
every enabled agent from require and prefer gates, fit against the
agent's intent, recency and company affinity, keeping gated rows with a
reason. Schema v3 adds vectors and the cached intent vector. The page
gets an agent order, the score on each row, and an Agents tab. Two
starter agents in roles.yaml are imported once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-23 12:14:21 +02:00
1 parent 4dfb8831aa
commit bc60324fab
22 files changed
+1457 -44

No files matched your search

+54 -7
View File
@@ -1,4 +1,4 @@
"""The JSON routes the page uses: roles, companies, applications.
"""The JSON routes the page uses: roles, companies, applications, agents.
`/api/jobs*`, `/_jobs/jobs.js` and `/ws/jobs` are `pipeline.web`'s, mounted by
`connect` in `app.py`. This is roledesk's own API, over the same store.
@@ -9,10 +9,12 @@ from __future__ import annotations
from datetime import timedelta
from typing import Annotated
from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from fastapi import APIRouter, HTTPException, Query, Response
from pydantic import BaseModel, Field
from roledesk.models import AFFINITY, Application, Company, Role, Status
from roledesk.models import (
AFFINITY, Agent, Application, Company, Gate, ScoredRole, Status, Weights,
)
from roledesk.web.deps import StoreDep
router = APIRouter(prefix="/api", tags=["roledesk"])
@@ -30,14 +32,21 @@ def list_roles(
remote: str = "",
days: int | None = None,
show_muted: bool = False,
agent: int | None = None,
gated: bool = False,
limit: Annotated[int, Query(ge=1, le=1000)] = 200,
) -> list[Role]:
) -> list[ScoredRole]:
"""Open roles, newest first. See `Store.roles` for what each filter does.
A muted company's roles are left out unless `show_muted` is set."""
A muted company's roles are left out unless `show_muted` is set. With
`agent`, ordered by that agent's score and carrying `score` and
`gated_reason`; a gated role only with `gated=1`."""
if agent is not None and store.agent(agent) is None:
raise HTTPException(404, f"no such agent: {agent}")
return store.roles(limit=limit, q=q or None, company=company or None,
place=place or None, function=function or None,
remote=remote or None, days=days, hide_muted=not show_muted)
remote=remote or None, days=days, hide_muted=not show_muted,
agent=agent, gated=gated)
# --------------------------------------------------------------- companies
@@ -122,3 +131,41 @@ def set_status(app_id: str, body: StatusBody, store: StoreDep) -> Application:
raise HTTPException(422, str(exc)) from exc
except KeyError:
raise HTTPException(404, f"no such application: {app_id}") from None
# ------------------------------------------------------------------ agents
@router.get("/agents")
def list_agents(store: StoreDep) -> list[Agent]:
return store.agents()
class AgentBody(BaseModel):
"""Create when `id` is missing, replace that agent's fields when given."""
id: int | None = None
name: str = Field(min_length=1)
intent: str = ""
gates: list[Gate] = []
weights: Weights = Weights()
enabled: bool = True
@router.post("/agents")
def save_agent(body: AgentBody, store: StoreDep) -> Agent:
"""Scores are not recomputed here: that is the `score` task, which the
page starts after a save."""
try:
return store.save_agent(body.name, body.intent, body.gates, body.weights,
body.enabled, agent_id=body.id)
except ValueError as exc:
raise HTTPException(409, str(exc)) from exc
except KeyError:
raise HTTPException(404, f"no such agent: {body.id}") from None
@router.delete("/agents/{agent_id}", status_code=204)
def delete_agent(agent_id: int, store: StoreDep) -> Response:
if not store.delete_agent(agent_id):
raise HTTPException(404, f"no such agent: {agent_id}")
return Response(status_code=204)