Skip to content

Commit 2a6ae24

Browse files
committed
fix:added graceful handling
1 parent 92028fa commit 2a6ae24

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lambda_agent/agent.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ def chat(self, user_input: str) -> tuple[str, TokenUsage]:
169169
# Log the user message to the full transcript
170170
self.transcript.log("user", user_input)
171171

172-
# Send the initial user message
173-
with Spinner():
174-
response = self.chat_session.send_message(payload)
175-
turn_usage = turn_usage + self._accumulate(response)
172+
try:
173+
# Send the initial user message
174+
with Spinner():
175+
response = self.chat_session.send_message(payload)
176+
turn_usage = turn_usage + self._accumulate(response)
177+
except Exception as e:
178+
return f"An error occurred while contacting the API: {str(e)}", turn_usage
176179

177180
# The loop will continue as long as Gemini decides to call tools
178181
while True:

lambda_agent/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ def main():
334334
"\n [bold yellow]⚠ Action cancelled by user.[/bold yellow]"
335335
)
336336
continue
337+
except Exception as e:
338+
console.print(
339+
f"\n [bold red]⚠ An unexpected error occurred: {str(e)}[/bold red]"
340+
)
341+
continue
337342

338343
except Exception as e:
339344
console.print(

0 commit comments

Comments
 (0)