Give a search agent several prompts and score a role by its best one
Migration 14 moves each non-empty agents.intent into agent_prompts as one prompt named after the agent, with its cached vector, and drops the three intent columns. A role's fit is the maximum over the agent's prompts of the calibrated cosine, and scores.prompt names the prompt that won. The agents API takes prompts and still takes intent; the role endpoint serves the agent's score and prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6afe24eaa
commit
4e3c3f130e
9 files changed
+552
-127
No files matched your search
+15
-10
@@ -16,8 +16,8 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from app import jobs
|
||||
from app.models import (
|
||||
AFFINITY, Agent, Application, Company, Gate, Limits, Role, RoleRow, Status,
|
||||
Subscription, Weights, company_key,
|
||||
AFFINITY, Agent, Application, Company, Gate, Limits, Prompts, Role, RoleRow,
|
||||
ScoredRole, Status, Subscription, Weights, company_key,
|
||||
)
|
||||
from app.storage import Store
|
||||
from app.web.deps import ConfigDep, StoreDep
|
||||
@@ -60,9 +60,10 @@ class VoteBody(BaseModel):
|
||||
|
||||
|
||||
@router.get("/roles/{uid}")
|
||||
def get_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
"""One role, open or closed, for the read page, with `agent`'s vote (the
|
||||
default agent's when absent; None when there is no agent)."""
|
||||
def get_role(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRole:
|
||||
"""One role, open or closed, for the read page, with `agent`'s vote and
|
||||
score, and the prompt that gave its fit (the default agent's when absent;
|
||||
None when there is no agent)."""
|
||||
role = store.role(uid, _agent_id(store, agent))
|
||||
if role is None:
|
||||
raise HTTPException(404, f"no such role: {uid}")
|
||||
@@ -70,7 +71,7 @@ def get_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
|
||||
|
||||
@router.post("/roles/{uid}/vote")
|
||||
def vote_role(uid: str, body: VoteBody, store: StoreDep) -> Role:
|
||||
def vote_role(uid: str, body: VoteBody, store: StoreDep) -> ScoredRole:
|
||||
"""1 like, 0 neither way, -1 pass, for `body.agent` or the default agent.
|
||||
The role stays listed either way; the vote moves it in that agent's
|
||||
ranking, see `Store.roles`, and shapes its taste at the next `score`."""
|
||||
@@ -82,7 +83,7 @@ def vote_role(uid: str, body: VoteBody, store: StoreDep) -> Role:
|
||||
|
||||
|
||||
@router.delete("/roles/{uid}/vote")
|
||||
def unvote_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
def unvote_role(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRole:
|
||||
"""Unjudged again for `agent` or the default agent: what pressing the
|
||||
stance a role already has does."""
|
||||
owner = _agent_or_default(store, agent)
|
||||
@@ -677,10 +678,13 @@ def list_agents(store: StoreDep) -> list[Agent]:
|
||||
|
||||
|
||||
class AgentBody(BaseModel):
|
||||
"""Create when `id` is missing, replace that agent's fields when given."""
|
||||
"""Create when `id` is missing, replace that agent's fields when given.
|
||||
`intent` is the body from before an agent had prompts: without `prompts`
|
||||
it is stored as one prompt named after the agent."""
|
||||
|
||||
id: int | None = None
|
||||
name: str = Field(min_length=1)
|
||||
prompts: Prompts | None = None
|
||||
intent: str = ""
|
||||
gates: list[Gate] = []
|
||||
weights: Weights = Weights()
|
||||
@@ -694,7 +698,8 @@ def save_agent(body: AgentBody, store: StoreDep) -> Agent:
|
||||
a save and waits on the job it answers with."""
|
||||
try:
|
||||
return store.save_agent(body.name, body.intent, body.gates, body.weights,
|
||||
body.enabled, agent_id=body.id, limits=body.limits)
|
||||
body.enabled, agent_id=body.id, limits=body.limits,
|
||||
prompts=body.prompts)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
except KeyError:
|
||||
@@ -703,7 +708,7 @@ def save_agent(body: AgentBody, store: StoreDep) -> Agent:
|
||||
|
||||
@router.delete("/agents/{agent_id}", status_code=204)
|
||||
def delete_agent(agent_id: int, store: StoreDep) -> Response:
|
||||
"""Its scores, votes and affinities go with it."""
|
||||
"""Its prompts, scores, votes and affinities go with it."""
|
||||
if not store.delete_agent(agent_id):
|
||||
raise HTTPException(404, f"no such agent: {agent_id}")
|
||||
return Response(status_code=204)
|
||||
Reference in new issue
Block a user