Give an agent a CV, languages, avoid and must texts, and read a posting's languages with a level and its deadline (migration 28)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed6d641373
commit
4fc474c437
15 files changed
+716
-79
No files matched your search
+202
-2
@@ -14,6 +14,7 @@ import json
|
||||
import re
|
||||
import sys
|
||||
import unicodedata
|
||||
from datetime import date
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Any, Literal, get_args
|
||||
@@ -782,6 +783,36 @@ AFFINITY = range(-1, 3)
|
||||
HandReason = Literal["", "unread", "robots", "blocked", "key", "group", "gone", "added"]
|
||||
HAND_REASONS: tuple[str, ...] = get_args(HandReason)
|
||||
|
||||
#: How well somebody speaks a language, lowest first: what an agent's CV
|
||||
#: states and what a posting asks for. The order is the comparison.
|
||||
LanguageLevel = Literal["basic", "conversational", "professional", "fluent", "native"]
|
||||
LANGUAGE_LEVELS: tuple[str, ...] = get_args(LanguageLevel)
|
||||
|
||||
#: Whether a posting requires a language or calls it a plus.
|
||||
LanguageKind = Literal["required", "plus"]
|
||||
|
||||
#: English names of the languages a posting in reach names, by ISO 639-1
|
||||
#: code, for `language_flag`'s note. A code not here is shown as it is.
|
||||
LANGUAGE_NAMES: dict[str, str] = {
|
||||
"ar": "Arabic", "bg": "Bulgarian", "cs": "Czech", "da": "Danish", "de": "German",
|
||||
"el": "Greek", "en": "English", "es": "Spanish", "et": "Estonian", "fi": "Finnish",
|
||||
"fo": "Faroese", "fr": "French", "hi": "Hindi", "hr": "Croatian", "hu": "Hungarian",
|
||||
"is": "Icelandic", "it": "Italian", "ja": "Japanese", "kl": "Greenlandic",
|
||||
"ko": "Korean", "lt": "Lithuanian", "lv": "Latvian", "nb": "Norwegian",
|
||||
"nl": "Dutch", "nn": "Norwegian", "no": "Norwegian", "pl": "Polish",
|
||||
"pt": "Portuguese", "ro": "Romanian", "ru": "Russian", "sk": "Slovak",
|
||||
"sl": "Slovenian", "sr": "Serbian", "sv": "Swedish", "tr": "Turkish",
|
||||
"uk": "Ukrainian", "zh": "Chinese",
|
||||
}
|
||||
|
||||
_LANGUAGE_CODE = re.compile(r"^[a-z]{2}$")
|
||||
|
||||
|
||||
def language_code(value: Any) -> str:
|
||||
"""An ISO 639-1 code, lowercased, or '' when `value` is not one."""
|
||||
code = str(value or "").strip().lower()
|
||||
return code if _LANGUAGE_CODE.match(code) else ""
|
||||
|
||||
|
||||
# -------------------------------------------------------------- posting dates
|
||||
|
||||
@@ -847,6 +878,16 @@ def posted_at(published_at: str, first_seen: str, host: str) -> str:
|
||||
return first_seen
|
||||
|
||||
|
||||
def iso_day(value: Any) -> str:
|
||||
"""A date as `YYYY-MM-DD` from an ISO date or timestamp ("2026-10-18",
|
||||
"2026-10-18T00:00:00"), or '' when `value` holds no real date."""
|
||||
text = str(value or "").strip()[:10]
|
||||
try:
|
||||
return date.fromisoformat(text).isoformat() if len(text) == 10 else ""
|
||||
except ValueError:
|
||||
return ""
|
||||
|
||||
|
||||
def _json(value: Any, empty: str) -> Any:
|
||||
"""A JSON text column as the Python value, tolerant like `JsonDict`: a
|
||||
value that is already parsed passes, and one that does not parse is the
|
||||
@@ -863,6 +904,129 @@ def _json(value: Any, empty: str) -> Any:
|
||||
JsonStrings = Annotated[list[str], BeforeValidator(lambda v: _json(v, "[]"))]
|
||||
|
||||
|
||||
def _json_list(value: Any) -> list[Any]:
|
||||
"""A nullable JSON array column as a list: NULL, a parse failure and
|
||||
anything but a list are []."""
|
||||
found = _json(value, "[]") if value is not None else []
|
||||
return found if isinstance(found, list) else []
|
||||
|
||||
|
||||
class CvLanguage(Model):
|
||||
"""A language an agent's CV states, with how well: `language` an ISO
|
||||
639-1 code, `level` one of `LANGUAGE_LEVELS`."""
|
||||
|
||||
language: str
|
||||
level: LanguageLevel
|
||||
|
||||
@field_validator("language", mode="before")
|
||||
@classmethod
|
||||
def _code(cls, value: Any) -> str:
|
||||
code = language_code(value)
|
||||
if not code:
|
||||
raise ValueError(f"a language is an ISO 639-1 code such as 'en', not {value!r}")
|
||||
return code
|
||||
|
||||
|
||||
def cv_languages(value: Any) -> list[CvLanguage]:
|
||||
"""An agent's languages as stored and sent: one per code, the first
|
||||
kept, in the order given."""
|
||||
seen: set[str] = set()
|
||||
out: list[CvLanguage] = []
|
||||
for item in _json_list(value):
|
||||
found = item if isinstance(item, CvLanguage) else CvLanguage.model_validate(item)
|
||||
if found.language not in seen:
|
||||
seen.add(found.language)
|
||||
out.append(found)
|
||||
return out
|
||||
|
||||
|
||||
#: An agent's languages, normalised by `cv_languages`.
|
||||
CvLanguages = Annotated[list[CvLanguage], BeforeValidator(cv_languages)]
|
||||
|
||||
|
||||
class RoleLanguage(Model):
|
||||
"""A language a posting names (`roles.languages_required`, read by
|
||||
`extract`): its ISO 639-1 code, the level asked for ('' when the posting
|
||||
does not say), and whether it is required or a plus."""
|
||||
|
||||
language: str
|
||||
level: Literal["", "basic", "conversational", "professional", "fluent", "native"] = ""
|
||||
kind: LanguageKind = "required"
|
||||
|
||||
|
||||
def _role_languages(value: Any) -> list[RoleLanguage]:
|
||||
out = []
|
||||
for item in _json_list(value):
|
||||
try:
|
||||
out.append(item if isinstance(item, RoleLanguage)
|
||||
else RoleLanguage.model_validate(item))
|
||||
except ValueError:
|
||||
continue
|
||||
return out
|
||||
|
||||
|
||||
#: `roles.languages_required`: NULL (never read) and [] are both no language.
|
||||
RoleLanguages = Annotated[list[RoleLanguage], BeforeValidator(_role_languages)]
|
||||
|
||||
LangFlag = Literal["missing", "below", "plus", ""]
|
||||
|
||||
|
||||
def _language_name(code: str) -> str:
|
||||
return LANGUAGE_NAMES.get(code, code)
|
||||
|
||||
|
||||
def _asked(language: RoleLanguage) -> str:
|
||||
name = _language_name(language.language)
|
||||
return f"{name} ({language.level})" if language.level else name
|
||||
|
||||
|
||||
def language_flag(required: list[RoleLanguage],
|
||||
mine: list[CvLanguage]) -> tuple[LangFlag, str]:
|
||||
"""`(flag, note)` for a posting's languages against an agent's.
|
||||
`missing` when a required language is not one of the agent's, `below`
|
||||
when the level it states is above the agent's, else `plus` when a plus
|
||||
language is one of the agent's, else ''. The note says why, as
|
||||
"requires Danish (fluent); yours: none". No flag when the agent states
|
||||
no languages: there is nothing to compare with."""
|
||||
if not mine:
|
||||
return "", ""
|
||||
levels = {m.language: m.level for m in mine}
|
||||
rank = LANGUAGE_LEVELS.index
|
||||
needed = [r for r in required if r.kind == "required"]
|
||||
missing = [r for r in needed if r.language not in levels]
|
||||
if missing:
|
||||
return "missing", "; ".join(f"requires {_asked(r)}; yours: none" for r in missing)
|
||||
below = [r for r in needed if r.level and rank(r.level) > rank(levels[r.language])]
|
||||
if below:
|
||||
return "below", "; ".join(f"requires {_asked(r)}; yours: {levels[r.language]}"
|
||||
for r in below)
|
||||
plus = [r for r in required if r.kind == "plus" and r.language in levels]
|
||||
if plus:
|
||||
return "plus", "; ".join(f"{_asked(r)} is a plus; yours: {levels[r.language]}"
|
||||
for r in plus)
|
||||
return "", ""
|
||||
|
||||
|
||||
def cv_score(skills: int, experience: int, career: int) -> float:
|
||||
"""The one number of a CV match, 0 to 100: skills and career weigh 30,
|
||||
experience 25 (docs/decisions.md, the CV match)."""
|
||||
return round((30 * skills + 25 * experience + 30 * career) / 85, 1)
|
||||
|
||||
|
||||
class Judgement(Model):
|
||||
"""What `judge` read of one role for one agent (`role_judgements`): the
|
||||
three dimensions 0 to 100, `cv_score` (`cv_score`), and 1 to 3 strengths
|
||||
and gaps grounded in the posting."""
|
||||
|
||||
skills: int
|
||||
experience: int
|
||||
career: int
|
||||
cv_score: float
|
||||
strengths: JsonStrings = []
|
||||
gaps: JsonStrings = []
|
||||
judged_at: str
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ models
|
||||
|
||||
class RoleCopy(Model):
|
||||
@@ -924,8 +1088,15 @@ class Role(Model):
|
||||
employment: str = ""
|
||||
function: str = ""
|
||||
permit: Permit = ""
|
||||
#: ISO 639-1 codes the posting says are required, lowercase.
|
||||
#: ISO 639-1 codes the posting says are required, lowercase: what the
|
||||
#: `languages` gate reads.
|
||||
languages: JsonStrings = []
|
||||
#: Every language the posting names, with the level it asks for and
|
||||
#: whether it is required or a plus (`extract`); [] until read.
|
||||
languages_required: RoleLanguages = []
|
||||
#: The last day to apply, `YYYY-MM-DD`: the host's own date, else the
|
||||
#: one `extract` read; None when neither says (`app.prep`).
|
||||
deadline: str | None = None
|
||||
description: str = ""
|
||||
feed_text: str = ""
|
||||
#: The short text the host's list carries, until `description` arrives.
|
||||
@@ -1013,6 +1184,13 @@ class ScoredRole(Role):
|
||||
#: The agent's prompt that gave the role its fit; "" when fit did not
|
||||
#: count (gated, no vector, no prompt with text).
|
||||
prompt: str = ""
|
||||
#: The agent's `judge` reading of the role against its CV, None until
|
||||
#: judged; `cv_score` is its total.
|
||||
judgement: Judgement | None = None
|
||||
cv_score: float | None = None
|
||||
#: The posting's languages against the agent's (`language_flag`).
|
||||
lang_flag: LangFlag = ""
|
||||
lang_note: str = ""
|
||||
|
||||
|
||||
#: How many characters `RoleRow.excerpt` keeps at most: the feed row's own
|
||||
@@ -1087,6 +1265,13 @@ class RoleRow(Model):
|
||||
#: As `Role.remote_where`: the area a remote hire may live in, '' when
|
||||
#: the role is not remote or does not say.
|
||||
remote_where: str = ""
|
||||
#: As `Role.deadline`: the last day to apply, None when nothing says.
|
||||
deadline: str | None = None
|
||||
#: As `ScoredRole`: the posting's languages against the agent's, and
|
||||
#: the total of the agent's `judge` reading, None until judged.
|
||||
lang_flag: LangFlag = ""
|
||||
lang_note: str = ""
|
||||
cv_score: float | None = None
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
@@ -1238,6 +1423,10 @@ class Limits(Model):
|
||||
extract_min: float = Field(0.55, ge=0, le=1)
|
||||
summarise_top: int = Field(30, ge=0)
|
||||
summarise_min: float = Field(0.65, ge=0, le=1)
|
||||
#: How deep `judge` reads an agent with a CV: a long answer per role,
|
||||
#: so between summarise's 30 and extract's 500.
|
||||
judge_top: int = Field(150, ge=0)
|
||||
judge_min: float = Field(0.55, ge=0, le=1)
|
||||
|
||||
|
||||
class Prompt(Model):
|
||||
@@ -1299,7 +1488,14 @@ class Agent(Model):
|
||||
`fetch_terms` are words a role must match for a big board read with the
|
||||
wide reach to send it (`app/jobs/reach.py`): the pull's terms are the
|
||||
union over the enabled agents, and an agent with none means no board is
|
||||
narrowed by words. They decide what is fetched, not what ranks."""
|
||||
narrowed by words. They decide what is fetched, not what ranks.
|
||||
|
||||
`cv_text`, `cv_languages`, `avoid_text` and `must_text` are what
|
||||
`judge` reads a role against: the CV, the languages it states with a
|
||||
level, what drains the person, and their must-haves and deal-breakers
|
||||
(soft, read by the model only; a hard rule is a gate). An agent without
|
||||
a CV is not judged, and one without languages flags none
|
||||
(`language_flag`)."""
|
||||
|
||||
id: int
|
||||
name: str
|
||||
@@ -1308,6 +1504,10 @@ class Agent(Model):
|
||||
weights: Annotated[Weights, BeforeValidator(lambda v: _json(v, "{}"))] = Weights()
|
||||
limits: Annotated[Limits, BeforeValidator(lambda v: _json(v, "{}"))] = Limits()
|
||||
fetch_terms: FetchTerms = []
|
||||
cv_text: str = ""
|
||||
cv_languages: CvLanguages = []
|
||||
avoid_text: str = ""
|
||||
must_text: str = ""
|
||||
enabled: bool = True
|
||||
created_at: str
|
||||
|
||||
|
||||
Reference in new issue
Block a user