Skip to content

Commit 59e228e

Browse files
committed
Add support for handling malformed function calls gracefully.
1 parent f070637 commit 59e228e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

agent.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
Content,
2323
Candidate,
2424
FunctionResponse,
25+
FinishReason,
2526
)
26-
import base64
2727
import time
2828
from rich.console import Console
2929
from rich.table import Table
@@ -262,6 +262,15 @@ def run_one_iteration(self) -> Literal["COMPLETE", "CONTINUE"]:
262262

263263
reasoning = self.get_text(candidate)
264264
function_calls = self.extract_function_calls(candidate)
265+
266+
# Retry the request in case of malformed FCs.
267+
if (
268+
not function_calls
269+
and not reasoning
270+
and candidate.finish_reason == FinishReason.MALFORMED_FUNCTION_CALL
271+
):
272+
return "CONTINUE"
273+
265274
if not function_calls:
266275
print(f"Agent Loop Complete: {reasoning}")
267276
self.final_reasoning = reasoning

0 commit comments

Comments
 (0)