Skip to content

Commit 382030d

Browse files
committed
updated parsing outputs of agents when agents output their thought process as well.
1 parent 94aad40 commit 382030d

File tree

4 files changed

+80
-66
lines changed

4 files changed

+80
-66
lines changed

src/area_generation/generator.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
from .scientist import AreaScientist
1616

1717

18-
logging.getLogger("autogen").setLevel(logging.WARNING)
19-
logging.getLogger("autogen_core").setLevel(logging.WARNING)
20-
logging.getLogger("autogen_ext").setLevel(logging.WARNING)
21-
2218
log = logging.getLogger("agentic_area_gen.generator")
2319

2420
lf = Langfuse(blocked_instrumentation_scopes=["autogen SingleThreadedAgentRuntime"])
25-
openlit.init(tracer=lf._otel_tracer, disable_batch=True)
21+
22+
23+
openlit.init(tracer=lf._otel_tracer, disable_metrics=True)
2624

2725

2826
async def generate_areas(cfg: DictConfig) -> None:

src/area_generation/moderator.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,37 @@ async def _merge_proposals(
144144
is_finalized = False
145145
try:
146146
parsed = json.loads(raw_content)
147+
log.info(f"Moderator parsed: {parsed}")
148+
revised_areas = parsed.get("areas", {})
147149
is_finalized = parsed.get("finalized", False)
150+
148151
except Exception:
149-
log.error(f"Error parsing final areas JSON: {raw_content}")
152+
log.error(f"Error parsing merged areas JSON: {raw_content}")
150153
raise
151154

152155
if is_finalized or round_num >= self._max_round - 1:
153156
log.info(f"Moderator finalizing areas after round {round_num}")
154-
await self._finalize_areas(raw_content)
157+
await self._finalize_areas(revised_areas)
155158
else:
156159
log.info(
157160
f"Moderator sending merged proposal for revision in round {round_num}"
158161
)
159-
self._round = round_num + 1
162+
163+
# Use the already parsed areas instead of parsing again
164+
revision_content = json.dumps(revised_areas)
160165

161166
# Send to scientists for revision
162167
await self.publish_message(
163168
ScientistRevisionRequest(
164-
scientist_id="A",
165-
moderator_proposal=raw_content,
166-
round=self._round,
169+
moderator_proposal=revision_content,
170+
round=round_num + 1,
167171
),
168172
topic_id=DefaultTopicId(),
169173
)
170174
await self.publish_message(
171175
ScientistRevisionRequest(
172-
scientist_id="B",
173-
moderator_proposal=raw_content,
174-
round=self._round,
176+
moderator_proposal=revision_content,
177+
round=round_num + 1,
175178
),
176179
topic_id=DefaultTopicId(),
177180
)
@@ -181,35 +184,19 @@ async def _merge_proposals(
181184
log.error(f"Traceback: {traceback.format_exc()}")
182185
raise
183186

184-
async def _finalize_areas(self, final_areas: str) -> None:
187+
async def _finalize_areas(self, final_areas: dict) -> None:
185188
"""Save final areas to file."""
186189
try:
187190
log.info("Moderator finalizing and saving areas")
188191

189-
# Convert to the expected format with "areas" list
190-
try:
191-
json_start = final_areas.find("{")
192-
if json_start != -1:
193-
json_part = final_areas[json_start:]
194-
parsed = json.loads(json_part)
195-
else:
196-
parsed = json.loads(final_areas)
197-
198-
if "finalized" in parsed:
199-
del parsed["finalized"] # Remove finalized flag
200-
201-
# Convert area_0, area_1 format to areas list
202-
areas_list = []
203-
i = 0
204-
while f"area_{i}" in parsed:
205-
areas_list.append(parsed[f"area_{i}"])
206-
i += 1
207-
208-
final_format = {"areas": areas_list}
209-
final_areas_json = json.dumps(final_format, indent=2)
210-
except Exception as e:
211-
log.warning(f"Could not parse final areas JSON: {e}")
212-
final_areas_json = final_areas
192+
areas_list = []
193+
i = 0
194+
while f"area_{i}" in final_areas:
195+
areas_list.append(final_areas[f"area_{i}"])
196+
i += 1
197+
198+
final_format = {"areas": areas_list}
199+
final_areas_json = json.dumps(final_format, indent=2)
213200

214201
self._save_areas_to_file(final_areas_json)
215202
log.info("Area generation completed successfully")

src/area_generation/scientist.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Area scientist agent for generating capability areas."""
22

3+
import json
34
import logging
45
import traceback
56

@@ -27,6 +28,7 @@
2728
ScientistRevisionRequest,
2829
)
2930

31+
3032
log = logging.getLogger("agentic_area_gen.scientist")
3133

3234

@@ -73,11 +75,20 @@ async def handle_area_proposal_request(
7375
if not isinstance(raw_content, str):
7476
raw_content = str(raw_content)
7577

78+
# Extract only the areas part for the proposal message
79+
proposal_content = raw_content
80+
try:
81+
parsed = json.loads(raw_content)
82+
proposal_content = json.dumps(parsed["areas"])
83+
except Exception as e:
84+
log.error(f"Could not parse scientist response as JSON: {e}")
85+
raise
86+
7687
log.info(f"Scientist {self._scientist_id} publishing area proposal")
7788
await self.publish_message(
7889
ScientistAreaProposal(
7990
scientist_id=self._scientist_id,
80-
proposal=raw_content,
91+
proposal=proposal_content,
8192
round=self._round,
8293
),
8394
topic_id=DefaultTopicId(),
@@ -119,13 +130,21 @@ async def handle_revision_request(
119130
if not isinstance(raw_content, str):
120131
raw_content = str(raw_content)
121132

133+
proposal_content = raw_content
134+
try:
135+
parsed = json.loads(raw_content)
136+
proposal_content = json.dumps(parsed["areas"])
137+
except Exception as e:
138+
log.error(f"Could not parse scientist revision response as JSON: {e}")
139+
raise
140+
122141
log.info(
123142
f"Scientist {self._scientist_id} publishing revised proposal for round {message.round}"
124143
)
125144
await self.publish_message(
126145
ScientistAreaProposal(
127146
scientist_id=self._scientist_id,
128-
proposal=raw_content,
147+
proposal=proposal_content,
129148
round=message.round,
130149
),
131150
topic_id=DefaultTopicId(),
@@ -136,4 +155,4 @@ async def handle_revision_request(
136155
f"Error in Scientist {self._scientist_id} handle_revision_request: {e}"
137156
)
138157
log.error(f"Traceback: {traceback.format_exc()}")
139-
raise
158+
raise

src/utils/agentic_prompts.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
1. A short name (a few words).
1616
2. A 2–3 sentence description that defines its boundaries and justifies its inclusion.
1717
18-
Please return your proposal in the following format:
19-
RESPONSE JSON:
18+
Please return your proposal and your thoughts and reasoning in the following format:
2019
{{
21-
"area_0": {{
22-
"name": <STR>,
23-
"description": <STR>
24-
}},
25-
...
20+
"thought": <STR>,
21+
"areas":
22+
{{
23+
"area_0": {{
24+
"name": <STR>,
25+
"description": <STR>
26+
}},
27+
...
28+
}}
2629
}}"""
2730

2831
AREA_SCIENTIST_REVISION_PROMPT = """You are Scientist {scientist_id}. You are reviewing the merged set of capability areas proposed by the Moderator.
@@ -37,16 +40,19 @@
3740
3841
Keep your feedback constructive and focused on improving clarity, coverage, and non-overlap. Avoid unnecessary changes.
3942
40-
Return your revised proposal with the following format:
41-
THOUGHT: <your summary of thoughts on the proposal and changes you made>
42-
RESPONSE JSON:
43+
Return your revised proposal and your thoughts and reasoning with the following format:
4344
{{
44-
"area_0": {{
45-
"name": <STR>,
46-
"description": <STR>
47-
}},
48-
...
49-
}}"""
45+
"thought": <STR>,
46+
"areas":
47+
{{
48+
"area_0": {{
49+
"name": <STR>,
50+
"description": <STR>
51+
}},
52+
...
53+
}}
54+
}}
55+
"""
5056

5157
AREA_MODERATOR_MERGE_PROMPT = """You are the Moderator. Two scientist agents have independently proposed a list of high-level capability areas for evaluating large language models in the domain of {domain}.
5258
@@ -66,14 +72,18 @@
6672
Explain how you merge the above proposals. Be thoughtful and concise in your output.
6773
You will then submit this merged proposal for review by the scientist agents. If either scientist provides substantive suggestions, you may revise the proposal and initiate another round of review.{finalized_instruction}
6874
69-
Present the merged areas in the following format:
70-
THOUGHT: <your summary of thoughts on the proposals and merges you made>
75+
Present the merged areas and your thoughts and reasoning in the following format:
7176
{{
72-
"area_0": {{
73-
"name": <STR>,
74-
"description": <STR>
75-
}},
76-
...{finalized_field}
77+
"thought": <STR>,
78+
"areas":
79+
{{
80+
"area_0": {{
81+
"name": <STR>,
82+
"description": <STR>
83+
}},
84+
...
85+
}}
86+
{finalized_field}
7787
}}
7888
"""
7989

@@ -267,4 +277,4 @@
267277
"finalized": true
268278
at the end of your JSON response."""
269279

270-
FINALIZED_FIELD = ', "finalized": <true|false>'
280+
FINALIZED_FIELD = '"finalized": <true|false>'

0 commit comments

Comments
 (0)