Repository navigation
Expand file tree
/
Copy pathassessment.py
More file actions
115 lines (88 loc) · 4 KB
/
Copy pathassessment.py
File metadata and controls
115 lines (88 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Structured assessment outputs produced by the readiness LLM step."""
from __future__ import annotations
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
from agent.domain.repo_context import RepoContext
ReadinessDecision = Literal["need_info", "ready", "cannot_assess"]
FollowUpField = Literal[
"repo_url",
"acceptance_criteria",
"owner",
"scope",
"other",
]
"""Canonical topic keys for :class:`FollowUpQuestion`.
The five values are the only ones the LLM may emit when populating a
``follow_up`` entry; ``with_structured_output(TicketAssessment)``
rejects any other string at the Pydantic boundary. The renderer
groups and prioritises questions by topic, and a ``"repo_url"``
follow-up always sorts to the top so a missing repository surfaces
first.
Topic semantics:
* ``"repo_url"`` — the agent could not identify a Git
repository for the issue (M4.6 ``RepoContext(must_request=True)``).
* ``"acceptance_criteria"`` — the issue lacks measurable acceptance
criteria; the agent cannot judge "done".
* ``"owner"`` — no responsible team / individual is
named for the work.
* ``"scope"`` — the proposed work is too broad to plan
in one ticket.
* ``"other"`` — anything else; the LLM must inline a
human-readable description in ``question``.
"""
_FOLLOW_UP_FIELD_PRIORITY: dict[FollowUpField, int] = {
"repo_url": 0,
"acceptance_criteria": 1,
"owner": 2,
"scope": 3,
"other": 4,
}
"""Sort order applied by :func:`follow_up_priority` (and the renderer).
Lower values surface first. Frozen because the renderer relies on the
exact ordering for deterministic Jira-comment output.
"""
def follow_up_priority(field: FollowUpField) -> int:
"""Return the sort priority for ``field`` (lower = higher priority)."""
return _FOLLOW_UP_FIELD_PRIORITY[field]
class FollowUpQuestion(BaseModel):
"""One concrete follow-up question the agent should ask in Jira.
``field`` is a :data:`FollowUpField` (a Literal of the five
canonical topic keys) so the renderer can group questions by topic
without parsing free-form strings, and so a port to a different
agent framework can validate the LLM's structured output against a
closed set.
Wave 8 adds ``target_custom_field_id``: when non-``None``, the
implementation-designer's post-comment renderer writes a
structured ``jira_set_custom_field`` MCP call that targets this
Jira custom-field id directly instead of (or in addition to)
appending a free-form Markdown comment. This is the
"machine-actionable" path operators wire up by setting the
per-tenant ``AGENT_REPO_URL_FIELD_ID`` env var (or its
Secrets-Manager-backed equivalent in the AWS profile); when the
var is absent the field is left ``None`` and the renderer falls
back to the free-form comment so the assessor's behaviour is
unchanged.
"""
model_config = ConfigDict(extra="forbid", frozen=True)
field: FollowUpField
question: str = Field(min_length=1)
target_custom_field_id: str | None = Field(default=None, min_length=1)
class TicketAssessment(BaseModel):
"""Validated readiness assessment for a Jira issue."""
model_config = ConfigDict(extra="forbid")
decision: ReadinessDecision
summary: str = Field(min_length=1)
follow_ups: tuple[FollowUpQuestion, ...] = Field(default_factory=tuple)
citations: tuple[str, ...] = Field(default_factory=tuple)
confidence: float = Field(ge=0.0, le=1.0)
# Optional so legacy fixtures and ``cannot_assess`` paths that have
# nothing useful to report still validate; persistence falls through
# to the previous ``TicketDomainState.repo_url`` / ``branch`` when
# ``None`` (the designer / repo-context handoff fallback).
repo_context: RepoContext | None = Field(default=None)
@property
def is_ready(self) -> bool:
return self.decision == "ready"
@property
def needs_info(self) -> bool:
return self.decision == "need_info"