PlanOpticon

planopticon / video_processor / agent / skills / requirements_chat.py
Blame History Raw 96 lines
1
"""Skill: Interactive requirements gathering via guided questions."""
2
3
import json
4
5
from video_processor.agent.skills.base import (
6
AgentContext,
7
Artifact,
8
Skill,
9
register_skill,
10
)
11
from video_processor.utils.json_parsing import parse_json_from_response
12
13
14
class RequirementsChatSkill(Skill):
15
name = "requirements_chat"
16
description = "Interactive requirements gathering via guided questions"
17
18
def execute(self, context: AgentContext, **kwargs) -> Artifact:
19
"""Generate a structured requirements questionnaire."""
20
stats = context.query_engine.stats()
21
entities = context.query_engine.entities()
22
23
parts = [
24
"You are a requirements analyst. Based on the following "
25
"knowledge graph context, generate a requirements "
26
"gathering questionnaire.",
27
"",
28
"## Knowledge Graph Overview",
29
stats.to_text(),
30
"",
31
"## Entities",
32
entities.to_text(),
33
"",
34
"## Planning Entities",
35
]
36
for e in context.planning_entities:
37
parts.append(f"- {e}")
38
39
parts.append(
40
'\nGenerate a JSON object with a "questions" array. '
41
"Each question should have:\n"
42
'- "id": string (e.g. "Q1")\n'
43
'- "category": "goals"|"constraints"|"priorities"|"scope"\n'
44
'- "question": string\n'
45
'- "context": string (why this matters)\n\n'
46
"Include 8-12 targeted questions.\n\n"
47
"Return ONLY the JSON."
48
)
49
50
prompt = "\n".join(parts)
51
response = context.provider_manager.chat(messages=[{"role": "user", "content": prompt}])
52
parsed = parse_json_from_response(response)
53
content = json.dumps(parsed, indent=2) if not isinstance(parsed, str) else parsed
54
55
return Artifact(
56
name="Requirements Questionnaire",
57
content=content,
58
artifact_type="requirements",
59
format="json",
60
metadata={"stage": "questionnaire"},
61
)
62
63
def gather_requirements(self, context: AgentContext, answers: dict) -> dict:
64
"""Take Q&A pairs and synthesize structured requirements."""
65
stats = context.query_engine.stats()
66
67
qa_text = ""
68
for qid, answer in answers.items():
69
qa_text += f"- {qid}: {answer}\n"
70
71
parts = [
72
"You are a requirements analyst. Based on the knowledge "
73
"graph context and the answered questions, synthesize "
74
"structured requirements.",
75
"",
76
"## Knowledge Graph Overview",
77
stats.to_text(),
78
"",
79
"## Answers",
80
qa_text,
81
"Return a JSON object with:\n"
82
'- "goals": list of goal strings\n'
83
'- "constraints": list of constraint strings\n'
84
'- "priorities": list (ordered high to low)\n'
85
'- "scope": {"in_scope": [...], "out_of_scope": [...]}\n\n'
86
"Return ONLY the JSON.",
87
]
88
89
prompt = "\n".join(parts)
90
response = context.provider_manager.chat(messages=[{"role": "user", "content": prompt}])
91
result = parse_json_from_response(response)
92
return result if isinstance(result, dict) else {"raw": result}
93
94
95
register_skill(RequirementsChatSkill())
96

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button