Spaces:
Runtime error
Runtime error
Add retry mechanism and `StopEvent` handling in `make_plan` for better formatting enforcement
Browse files
src/gaia_solving_agent/agent.py
CHANGED
|
@@ -57,6 +57,7 @@ def get_llm(model_name=cheap_model_name):
|
|
| 57 |
class PlanEvent(Event):
|
| 58 |
to_do: Literal["Initialize", "Format", "Replan"] = "Initialize"
|
| 59 |
plan: str | None = None
|
|
|
|
| 60 |
|
| 61 |
class QueryEvent(Event):
|
| 62 |
pass
|
|
@@ -75,7 +76,7 @@ class GaiaWorkflow(Workflow):
|
|
| 75 |
return PlanEvent()
|
| 76 |
|
| 77 |
@step
|
| 78 |
-
async def make_plan(self, ctx: Context, ev: PlanEvent) -> PlanEvent | QueryEvent:
|
| 79 |
additional_file_path = await ctx.store.get("additional_file_path")
|
| 80 |
user_msg = await ctx.store.get("user_msg")
|
| 81 |
|
|
@@ -92,16 +93,22 @@ class GaiaWorkflow(Workflow):
|
|
| 92 |
...
|
| 93 |
# TODO : Placeholder for future update
|
| 94 |
elif ev.to_do == "Format":
|
|
|
|
|
|
|
| 95 |
prompt = f"""
|
| 96 |
The original plan is not in the correct format.
|
| 97 |
|
|
|
|
| 98 |
There is the query and constraints you must respect :
|
| 99 |
{prompt}
|
| 100 |
|
|
|
|
| 101 |
There is the original plan you must reformat :
|
| 102 |
{ev.plan}
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
"""
|
| 106 |
|
| 107 |
plan = llm.complete(prompt)
|
|
@@ -114,7 +121,7 @@ Stick strictly to the formatting constraints !
|
|
| 114 |
extracted is None
|
| 115 |
for extracted in [question, known_facts, sub_tasks]
|
| 116 |
):
|
| 117 |
-
return PlanEvent(to_do="Format", plan=plan.text)
|
| 118 |
else:
|
| 119 |
await ctx.store.set("question", question if question is not None else "")
|
| 120 |
await ctx.store.set("known_facts", known_facts if known_facts is not None else "")
|
|
|
|
| 57 |
class PlanEvent(Event):
|
| 58 |
to_do: Literal["Initialize", "Format", "Replan"] = "Initialize"
|
| 59 |
plan: str | None = None
|
| 60 |
+
n_retries: int = 0
|
| 61 |
|
| 62 |
class QueryEvent(Event):
|
| 63 |
pass
|
|
|
|
| 76 |
return PlanEvent()
|
| 77 |
|
| 78 |
@step
|
| 79 |
+
async def make_plan(self, ctx: Context, ev: PlanEvent) -> PlanEvent | QueryEvent | StopEvent:
|
| 80 |
additional_file_path = await ctx.store.get("additional_file_path")
|
| 81 |
user_msg = await ctx.store.get("user_msg")
|
| 82 |
|
|
|
|
| 93 |
...
|
| 94 |
# TODO : Placeholder for future update
|
| 95 |
elif ev.to_do == "Format":
|
| 96 |
+
if ev.n_retries > 3:
|
| 97 |
+
return StopEvent(result="Cannot provide a plan. Format may be wrong.", reasoning=ev.plan)
|
| 98 |
prompt = f"""
|
| 99 |
The original plan is not in the correct format.
|
| 100 |
|
| 101 |
+
______________
|
| 102 |
There is the query and constraints you must respect :
|
| 103 |
{prompt}
|
| 104 |
|
| 105 |
+
______________
|
| 106 |
There is the original plan you must reformat :
|
| 107 |
{ev.plan}
|
| 108 |
|
| 109 |
+
______________
|
| 110 |
+
Ask yourself what you did wrong and fix it.
|
| 111 |
+
Stick strictly to the formatting constraints !
|
| 112 |
"""
|
| 113 |
|
| 114 |
plan = llm.complete(prompt)
|
|
|
|
| 121 |
extracted is None
|
| 122 |
for extracted in [question, known_facts, sub_tasks]
|
| 123 |
):
|
| 124 |
+
return PlanEvent(to_do="Format", plan=plan.text, n_retries=ev.n_retries + 1)
|
| 125 |
else:
|
| 126 |
await ctx.store.set("question", question if question is not None else "")
|
| 127 |
await ctx.store.set("known_facts", known_facts if known_facts is not None else "")
|