kumar-aditya commited on
Commit
15504d3
·
verified ·
1 Parent(s): 570c20b

Create agents.py

Browse files
Files changed (1) hide show
  1. agents.py +111 -0
agents.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from langchain_core.output_parsers import PydanticOutputParser
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+
6
+ from schemas import CodeAnalysis, FeedbackSignal, Spec, TestCaseList, TestPlan
7
+
8
+
9
+ def build_spec_agent(llm):
10
+ parser = PydanticOutputParser(pydantic_object=Spec)
11
+ prompt = ChatPromptTemplate.from_messages(
12
+ [
13
+ (
14
+ "system",
15
+ "You extract structured requirements from problem statements. "
16
+ "Return JSON only that matches the schema. No markdown.",
17
+ ),
18
+ (
19
+ "human",
20
+ "Problem statement:\n{problem}\n\n"
21
+ "User-provided description:\n{description}\n\n"
22
+ "User-provided constraints:\n{constraints}\n\n"
23
+ "Language: {language}\n\n"
24
+ "{format_instructions}",
25
+ ),
26
+ ]
27
+ )
28
+ return prompt, parser
29
+
30
+
31
+ def build_code_analysis_agent(llm):
32
+ parser = PydanticOutputParser(pydantic_object=CodeAnalysis)
33
+ prompt = ChatPromptTemplate.from_messages(
34
+ [
35
+ (
36
+ "system",
37
+ "Analyze code behavior and risks. Return JSON only. No markdown.",
38
+ ),
39
+ (
40
+ "human",
41
+ "Language: {language}\n\nCode:\n{code}\n\n{format_instructions}",
42
+ ),
43
+ ]
44
+ )
45
+ return prompt, parser
46
+
47
+
48
+ def build_test_plan_agent(llm):
49
+ parser = PydanticOutputParser(pydantic_object=TestPlan)
50
+ prompt = ChatPromptTemplate.from_messages(
51
+ [
52
+ (
53
+ "system",
54
+ "Create a structured testing plan with targets per category. "
55
+ "Return JSON only. No markdown.",
56
+ ),
57
+ (
58
+ "human",
59
+ "Spec:\n{spec}\n\nCode analysis:\n{analysis}\n\n"
60
+ "Known issues from previous iteration:\n{issues}\n\n"
61
+ "Required categories: Basic cases, boundary cases, random cases, "
62
+ "stress cases, invalid/robustness cases, bug-targeted cases.\n"
63
+ "Desired per-category count: {per_category}\n\n"
64
+ "{format_instructions}",
65
+ ),
66
+ ]
67
+ )
68
+ return prompt, parser
69
+
70
+
71
+ def build_feedback_agent(llm):
72
+ parser = PydanticOutputParser(pydantic_object=FeedbackSignal)
73
+ prompt = ChatPromptTemplate.from_messages(
74
+ [
75
+ (
76
+ "system",
77
+ "Assess test plan quality. Return JSON only. No markdown.",
78
+ ),
79
+ (
80
+ "human",
81
+ "Spec:\n{spec}\n\nPlan:\n{plan}\n\n"
82
+ "Detected issues so far:\n{issues}\n\n"
83
+ "{format_instructions}",
84
+ ),
85
+ ]
86
+ )
87
+ return prompt, parser
88
+
89
+
90
+ def build_test_generator_agent(llm):
91
+ parser = PydanticOutputParser(pydantic_object=TestCaseList)
92
+ prompt = ChatPromptTemplate.from_messages(
93
+ [
94
+ (
95
+ "system",
96
+ "Generate concrete test cases. Use plan.targets for counts. "
97
+ "Return JSON only. No markdown. "
98
+ "Do not use code, expressions, or functions. "
99
+ "All values must be literal JSON (strings, numbers, arrays, objects). "
100
+ "Do not use repeat or operators. "
101
+ "Keep any single string length <= 200 characters.",
102
+ ),
103
+ (
104
+ "human",
105
+ "Spec:\n{spec}\n\nPlan:\n{plan}\n\n"
106
+ "Student index: {student_id}\n\n"
107
+ "{format_instructions}",
108
+ ),
109
+ ]
110
+ )
111
+ return prompt, parser