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:
WolfandClaude Opus 5.5 committed 2026-10-03 21:54:16 +02:00
1 parent ed6d641373
commit 4fc474c437
15 files changed
+716 -79

No files matched your search

+76 -18
View File
@@ -10,8 +10,9 @@ refused batch, and failing with a notice when no model is reachable are
`extract` is also the afterburner for the level and the remote area. A role
is waiting while it is open, has not been given up on, has never been
answered (`extracted_at IS NULL`), has no model level (`seniority_model`
empty) or was never asked where a remote hire may live (`remote_where_model`
NULL), and is in the best of an enabled agent's
empty), was never asked where a remote hire may live (`remote_where_model`
NULL) or for its languages and deadline (`languages_required` NULL), and is
in the best of an enabled agent's
ungated scores as deep and as low as that agent's own `limits` say
(`extract_top`, `extract_min`). That bound is what keeps the cost
proportional to the rankings rather than to the boards:
@@ -47,7 +48,10 @@ from pipeline import NULL, RunContext, Task, job
from app import prep
from app.config import Config
from app.jobs import stages
from app.models import LEVELS, PERMITS, REMOTE, SENIORITIES, ExtractResult, Role
from app.models import (
LANGUAGE_LEVELS, LEVELS, PERMITS, REMOTE, SENIORITIES, ExtractResult, Role, iso_day,
language_code,
)
from app.storage import Store
# `FUNCTIONS` is the `ats` plugin's vocabulary, reached the way `web/pages.py`
@@ -58,10 +62,13 @@ if str(_ROOT) not in sys.path:
from plugins.ats import FUNCTIONS # noqa: E402
#: How much of the description goes in one item. Salary, place and remote are
#: nearly always in the opening or the closing lines of an ad; the first 3000
#: characters hold most of them at a fifth of a long posting's tokens.
EXCERPT = 3000
#: How much of the description goes in one item: the opening `HEAD` and the
#: closing `TAIL` characters, joined by an ellipsis when the text is longer.
#: Salary, place and remote are nearly always in the opening lines of an ad,
#: and the languages and the deadline in the closing ones.
HEAD = 2500
TAIL = 1500
EXCERPT = HEAD + TAIL
SYSTEM = f"""You read job postings and fill in structured fields, one answer per posting.
@@ -116,11 +123,32 @@ Fields:
- function: one of {", ".join(FUNCTIONS)}, or ''.
- permit: "sponsors" if the posting says it sponsors a visa or work permit,
"no_sponsorship" if it says it does not, else ''.
- languages_required: ISO 639-1 codes ("de", "en") of the languages the posting
says are required. Not ones it calls a plus. [] when it names none."""
- languages_required: every language the posting asks the hire to speak, one
entry each: `language` its ISO 639-1 code ("da", "en", "de"), `level` the
level it asks for, one of {", ".join(LANGUAGE_LEVELS)} (lowest first), or ''
when it states none, and `kind` "required" when the posting requires it,
"plus" when it calls it an advantage or nice to have. "Mother tongue" is
native; "fluent", "excellent" or "business fluent" is fluent; "very good",
"strong" or "professional working" is professional; "good", "working
knowledge" or "conversational" is conversational. The language the posting
is written in is not a requirement unless it says so. [] when it names none.
- deadline: the last day to apply as YYYY-MM-DD when the posting states a
date ("Ansøgningsfrist: 18.10.2026", "apply by 15 October"); with no year,
the first such date after `posted`. '' for none, "as soon as possible" or a
rolling review ("løbende")."""
_TEXT = {"type": "string"}
_SALARY = {"type": ["integer", "null"]}
_LANGUAGE_ITEM: dict[str, Any] = {
"type": "object",
"properties": {
"language": _TEXT,
"level": {"type": "string", "enum": ["", *LANGUAGE_LEVELS]},
"kind": {"type": "string", "enum": ["required", "plus"]},
},
"required": ["language", "level", "kind"],
"additionalProperties": False,
}
SCHEMA: dict[str, Any] = {
"type": "object",
@@ -141,11 +169,12 @@ SCHEMA: dict[str, Any] = {
"currency": _TEXT,
"function": {"type": "string", "enum": ["", *FUNCTIONS]},
"permit": {"type": "string", "enum": list(PERMITS)},
"languages_required": {"type": "array", "items": _TEXT},
"languages_required": {"type": "array", "items": _LANGUAGE_ITEM},
"deadline": _TEXT,
},
"required": ["uid", "place", "country", "remote", "remote_where", "seniority",
"salary_min", "salary_max", "currency", "function",
"permit", "languages_required"],
"permit", "languages_required", "deadline"],
"additionalProperties": False,
},
},
@@ -156,7 +185,6 @@ SCHEMA: dict[str, Any] = {
_COUNTRY = re.compile(r"^[A-Z]{2}$")
_CURRENCY = re.compile(r"^[A-Z]{3}$")
_LANGUAGE = re.compile(r"^[a-z]{2}$")
# ------------------------------------------------------------------- batches
@@ -164,12 +192,14 @@ _LANGUAGE = re.compile(r"^[a-z]{2}$")
def _item(role: Role) -> dict[str, Any]:
"""One posting as the model sees it. `location` is the board's own place
text where it gave one: part of the posting, and often the only line that
names the country."""
text = " ".join(role.description.split())[:EXCERPT]
names the country. `posted` is the day the role counts as posted, for a
deadline that names no year."""
text = excerpt(role.description)
return {key: value for key, value in {
"uid": role.uid,
"title": role.title,
"location": role.place,
"posted": role.posted_at[:10],
"stated": role.seniority_stated,
"title_level": role.seniority_title,
"text": text,
@@ -177,6 +207,15 @@ def _item(role: Role) -> dict[str, Any]:
}.items() if value}
def excerpt(text: str) -> str:
"""The text with its whitespace collapsed: whole up to `EXCERPT`
characters, else its opening `HEAD` and closing `TAIL` characters."""
flat = " ".join(text.split())
if len(flat) <= EXCERPT:
return flat
return f"{flat[:HEAD]} … {flat[-TAIL:]}"
def build_batch(config: Config, store: Store, limit: int = 20,
uids: Sequence[str] | None = None) -> dict[str, Any]:
return {"instructions": SYSTEM,
@@ -213,12 +252,29 @@ def _names(value: Any) -> list[str]:
return list(dict.fromkeys(name for name in found if name))[:_WHERE_NAMES]
def _languages(value: Any) -> list[dict[str, str]]:
"""`languages_required` checked: an entry per code, the first kept, with
a level of the ladder or '', and `required` unless it says `plus`. A
bare code, as an older reply gave, is a requirement with no level."""
found: dict[str, dict[str, str]] = {}
for raw in value if isinstance(value, list) else []:
one = raw if isinstance(raw, dict) else {"language": raw}
code = language_code(one.get("language"))
if not code or code in found:
continue
found[code] = {"language": code,
"level": _pick(one.get("level"), LANGUAGE_LEVELS),
"kind": "plus" if one.get("kind") == "plus" else "required"}
return list(found.values())
def fields(answer: dict[str, Any]) -> dict[str, Any]:
"""One answer, checked field by field. Anything outside a field's
vocabulary is '' or None, which `set_extracted` never writes, except
for `remote` and `remote_where`, which it writes as they come."""
languages = [code for raw in answer.get("languages_required") or []
if (code := _code(raw, _LANGUAGE, upper=False))]
for `remote`, `remote_where`, `languages_required` and `deadline`, which
it writes as they come. `languages` is the required codes, for the
`languages` gate."""
named = _languages(answer.get("languages_required"))
return {
"place": " ".join(str(answer.get("place") or "").split())[:200],
"country": _code(answer.get("country"), _COUNTRY, upper=True),
@@ -230,7 +286,9 @@ def fields(answer: dict[str, Any]) -> dict[str, Any]:
"currency": _code(answer.get("currency"), _CURRENCY, upper=True),
"function": _pick(answer.get("function"), FUNCTIONS),
"permit": _pick(answer.get("permit"), PERMITS),
"languages": list(dict.fromkeys(languages)),
"languages": [one["language"] for one in named if one["kind"] == "required"],
"languages_required": named,
"deadline": iso_day(answer.get("deadline")),
}