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:
1 parent
4dfb8831aa
commit
bc60324fab
22 files changed
+1457
-44
No files matched your search
+66
-1
@@ -15,7 +15,7 @@ import re
|
||||
import unicodedata
|
||||
from typing import Annotated, Any, Literal, get_args
|
||||
|
||||
from pydantic import BeforeValidator
|
||||
from pydantic import BeforeValidator, Field
|
||||
|
||||
from desk.models import JsonDict, Model, ModelTaskResult
|
||||
|
||||
@@ -152,6 +152,14 @@ class ExtractResult(ModelTaskResult):
|
||||
return self.extracted
|
||||
|
||||
|
||||
class ScoredRole(Role):
|
||||
"""A role as `/api/roles` serves it: with one agent's score and gate
|
||||
reason when an agent was asked for, and without otherwise."""
|
||||
|
||||
score: float | None = None
|
||||
gated_reason: str = ""
|
||||
|
||||
|
||||
class Company(Model):
|
||||
key: str
|
||||
name: str
|
||||
@@ -202,6 +210,63 @@ class Application(Model):
|
||||
updated_at: str = ""
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ agents
|
||||
|
||||
#: The role columns a gate can name. `company` matches on the company key;
|
||||
#: `place` is a case-insensitive substring, like the place filter; the rest are
|
||||
#: case-insensitive equality, except `salary_min` (at least the value) and
|
||||
#: `languages` (every language the role requires is one of the values).
|
||||
GateField = Literal["place", "country", "remote", "seniority", "function", "salary_min",
|
||||
"currency", "permit", "languages", "company"]
|
||||
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
|
||||
|
||||
GateMode = Literal["require", "prefer"]
|
||||
|
||||
|
||||
class Gate(Model):
|
||||
"""One condition of an agent. `require` gates a role that fails it (the
|
||||
row is kept with the reason); `prefer` adds `weight` to its score when it
|
||||
matches."""
|
||||
|
||||
field: GateField
|
||||
values: list[str | int | float] = Field(min_length=1)
|
||||
mode: GateMode = "require"
|
||||
weight: float = Field(1.0, ge=0)
|
||||
|
||||
|
||||
class Weights(Model):
|
||||
"""How much each score term counts. Summed with the prefer gates' weights
|
||||
into the denominator, so a score stays in 0..1 whatever the numbers."""
|
||||
|
||||
fit: float = Field(0.6, ge=0)
|
||||
recency: float = Field(0.2, ge=0)
|
||||
affinity: float = Field(0.2, ge=0)
|
||||
|
||||
|
||||
class Agent(Model):
|
||||
"""A row of `agents`: a named search with its own intent, gates and
|
||||
weights. The cached intent vector is a column this does not declare."""
|
||||
|
||||
id: int
|
||||
name: str
|
||||
intent: str = ""
|
||||
gates: Annotated[list[Gate], BeforeValidator(lambda v: _json(v, "[]"))] = []
|
||||
weights: Annotated[Weights, BeforeValidator(lambda v: _json(v, "{}"))] = Weights()
|
||||
enabled: bool = True
|
||||
created_at: str
|
||||
|
||||
|
||||
class Candidate(Model):
|
||||
"""What scoring reads about one open role for one agent: when it was
|
||||
first seen, its company's affinity, and per gate `1` match, `0` no
|
||||
match, `-1` the column is empty."""
|
||||
|
||||
uid: str
|
||||
first_seen: str
|
||||
affinity: int = 0
|
||||
gates: list[int] = []
|
||||
|
||||
|
||||
class ApplicationEvent(Model):
|
||||
id: int
|
||||
application_id: str
|
||||
|
||||
Reference in new issue
Block a user