-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
199 lines (158 loc) · 6.87 KB
/
Copy pathschemas.py
File metadata and controls
199 lines (158 loc) · 6.87 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from __future__ import annotations
import uuid
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
from backend.models.enums import AgentPhase, AmbiguityLevel, ContextSource, PipelineStatus, WSMessageType
# ---------------------------------------------------------------------------
# Agent I/O schemas (inter-agent message protocol)
# ---------------------------------------------------------------------------
class IntentSchema(BaseModel):
"""Output of Phase 1 / Input to Phase 2."""
goal: str
context: str = ""
constraints: list[str] = Field(default_factory=list)
expected_output_format: str = ""
success_criteria: list[str] = Field(default_factory=list)
alternative_interpretations: list[str] = Field(default_factory=list)
confidence: float = Field(ge=0.0, le=1.0, default=0.5)
raw_input: str = ""
class AmbiguityFlag(BaseModel):
dimension: str
description: str
level: AmbiguityLevel = AmbiguityLevel.LOW
impact: str = ""
class AmbiguityReport(BaseModel):
"""Output of Phase 2 / Input to Phase 3."""
intent: IntentSchema
flags: list[AmbiguityFlag] = Field(default_factory=list)
overall_ambiguity: AmbiguityLevel = AmbiguityLevel.LOW
needs_clarification: bool = False
reasoning: str = ""
class ClarificationQuestion(BaseModel):
question: str
why_needed: str = ""
dimension: str = ""
priority: int = 1
options: list[str] = Field(default_factory=list)
auto_resolved: bool = False
auto_answer: str = ""
auto_answer_source: str = ""
class ClarificationRequest(BaseModel):
"""Output of Phase 3 when questions are needed."""
questions: list[ClarificationQuestion] = Field(default_factory=list)
search_context: list[dict] = Field(
default_factory=list,
description="Web search results that informed the questions (title, url, snippet).",
)
auto_resolved_count: int = 0
class ClarifiedIntent(BaseModel):
"""Output of Phase 3 after user answers / Input to Phase 4."""
original_intent: IntentSchema
clarifications: dict[str, str] = Field(default_factory=dict)
refined_goal: str = ""
refined_constraints: list[str] = Field(default_factory=list)
refined_output_format: str = ""
class PlanStep(BaseModel):
step_number: int
description: str
inputs: list[str] = Field(default_factory=list)
expected_output: str = ""
dependencies: list[int] = Field(default_factory=list)
validation: str = ""
class ExecutionPlan(BaseModel):
"""Output of Phase 4 / Input to Phase 5."""
objective: str = ""
inputs: list[str] = Field(default_factory=list)
steps: list[PlanStep] = Field(default_factory=list)
deliverables: list[str] = Field(default_factory=list)
validation_checkpoints: list[str] = Field(default_factory=list)
class ContextItem(BaseModel):
"""A single retrieved context entry from one source."""
source: ContextSource
query: str = ""
content: str = ""
relevance: str = ""
source_detail: str = "" # doc name, URL, phase name, or step number
reasoning_trace: str = "" # PageIndex hierarchical reasoning path
metadata: dict = Field(default_factory=dict)
class ToolRequirement(BaseModel):
"""Describes one retrieval tool needed to gather context for a step."""
tool_name: str # "pageindex", "exa_search", "prior_context", "step_dep"
purpose: str = ""
queries: list[str] = Field(default_factory=list)
doc_filter: list[str] = Field(default_factory=list) # PageIndex: which docs
priority: str = "required" # "required" | "optional"
class StepContext(BaseModel):
"""All retrieved context for a single execution step."""
step_number: int
step_description: str = ""
required_tools: list[ToolRequirement] = Field(default_factory=list)
gathered_contexts: list[ContextItem] = Field(default_factory=list)
context_summary: str = "" # LLM-synthesised briefing for this step
execution_strategy: str = "" # recommended approach given gathered context
class ResourcePlan(BaseModel):
"""Structured resource and context plan for the full execution."""
objective: str = ""
total_steps: int = 0
tool_inventory: list[dict] = Field(default_factory=list)
step_contexts: list[StepContext] = Field(default_factory=list)
dependency_graph: dict = Field(default_factory=dict)
knowledge_base_docs_used: list[str] = Field(default_factory=list)
web_searches_performed: int = 0
estimated_complexity: str = ""
class StepResult(BaseModel):
step_number: int
output: str = ""
status: str = "completed"
validation_passed: bool = True
contexts_used: list[str] = Field(default_factory=list)
reasoning: str = ""
class ExecutionResult(BaseModel):
"""Output of Phase 5 — the final deliverable."""
plan: ExecutionPlan | None = None
resource_plan: ResourcePlan | None = None
step_results: list[StepResult] = Field(default_factory=list)
final_output: str = ""
completeness_check: str = ""
clarity_check: str = ""
relevance_check: str = ""
correctness_check: str = ""
trace_to_goal: str = ""
blob_url: str = "" # Vercel Blob public URL of the rendered HTML output
# ---------------------------------------------------------------------------
# WebSocket message envelope
# ---------------------------------------------------------------------------
class WSMessage(BaseModel):
type: WSMessageType
session_id: str = ""
phase: Optional[AgentPhase] = None
data: dict = Field(default_factory=dict)
timestamp: datetime = Field(default_factory=datetime.utcnow)
message_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
# ---------------------------------------------------------------------------
# Session state
# ---------------------------------------------------------------------------
class SessionState(BaseModel):
session_id: str
status: PipelineStatus = PipelineStatus.RUNNING
current_phase: Optional[AgentPhase] = None
user_input: str = ""
intent: Optional[IntentSchema] = None
ambiguity_report: Optional[AmbiguityReport] = None
clarification_request: Optional[ClarificationRequest] = None
clarified_intent: Optional[ClarifiedIntent] = None
execution_plan: Optional[ExecutionPlan] = None
resource_plan: Optional[ResourcePlan] = None
execution_result: Optional[ExecutionResult] = None
created_at: datetime = Field(default_factory=datetime.utcnow)
# ---------------------------------------------------------------------------
# Artifact
# ---------------------------------------------------------------------------
class Artifact(BaseModel):
artifact_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
session_id: str
artifact_type: str
title: str
content: dict = Field(default_factory=dict)
created_at: datetime = Field(default_factory=datetime.utcnow)