Skip to content

Conversation

@gvdongen
Copy link
Collaborator

@gvdongen gvdongen commented May 26, 2025

This pull request introduces logging enhancements, error handling improvements, and code cleanup across multiple files. It also updates the restate_sdk dependency version and refines agent behavior in the common/agent_session.py file. Below is a categorized summary of the most significant changes:

Logging Enhancements:

  • Added a consistent logging configuration to agents/native_restate/__main__.py and agents/openai_sdk/__main__.py for improved debugging and monitoring. [1] [2]

Error Handling Improvements:

  • Introduced a custom AgentError exception in common/agent_session.py to provide more meaningful error messages and feed errors back into the agent loop.
  • Replaced generic exceptions with ValidationError in common/a2a_middleware.py for better specificity during request validation.
  • Updated various error-raising scenarios in common/agent_session.py to use AgentError, ensuring consistent handling and feedback to the agent loop. [1] [2] [3] [4]

Code Cleanup and Refactoring:

  • Removed unused imports and variables, such as ResponseOutputText and A2AClientHTTPError, from common/agent_session.py to simplify the codebase. [1] [2]
  • Refactored the run_agent function in common/agent_session.py to remove the force_starting_agent logic and streamline agent selection. [1] [2]

Dependency Updates:

  • Updated the restate_sdk dependency in pyproject.toml from version 0.7.2 to 0.7.3 to incorporate the latest SDK features.

Agent Behavior Refinements:

  • Adjusted the handling of tool calls and remote agent responses to improve error messaging and retry logic in common/agent_session.py. [1] [2] [3]

@gvdongen gvdongen requested a review from Copilot May 26, 2025 14:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances logging, refines error handling with a custom AgentError, performs code cleanup, and updates the restate_sdk dependency.

  • Added consistent logging configuration in both agent entrypoints.
  • Introduced AgentError and replaced broad exception catches in common/agent_session.py.
  • Bumped restate_sdk from 0.7.2 to 0.7.3 for the latest SDK.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyproject.toml Updated restate_sdk dependency version
common/agent_session.py Removed unused imports, added AgentError, refactored error handling and run_agent logic
common/a2a_middleware.py Scoped exception catch to ValidationError
agents/openai_sdk/main.py Configured basic logging
agents/native_restate/main.py Configured basic logging
Comments suppressed due to low confidence (2)

common/agent_session.py:361

  • [nitpick] The loop variable ag is ambiguous. Renaming it to a more descriptive name like agent or a would make the comprehension clearer.
agents_dict = {ag.formatted_name: ag for ag in req.agents}

common/agent_session.py:713

  • Network or HTTP errors from client.post (e.g., timeouts, connection failures) are not caught and will raise outside this function. Consider catching httpx.RequestError and wrapping it in AgentError so the agent loop can handle and report these failures.
resp = await client.post(

agents_dict, response.output, tools
)
except Exception as e:
except AgentError as e:
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limiting the exception catch to only AgentError means other exceptions (e.g., JSON parse errors or unexpected runtime errors) will propagate and potentially crash the agent loop. Consider adding a broader except Exception (or a fallback) that logs or wraps other errors into AgentError to maintain loop resilience.

Copilot uses AI. Check for mistakes.
# We add it to the session_state to feed it back into the next LLM call
else:
raise e
except TerminalError as e:
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching only TerminalError here will allow other runtime exceptions (e.g., network issues, coding bugs) to escape and crash execution. You may want to reintroduce handling for SuspendedException and/or a generic fallback to ensure unexpected errors are surfaced back into the agent via AgentError.

Copilot uses AI. Check for mistakes.
@gvdongen gvdongen merged commit 512810e into main May 27, 2025
@gvdongen gvdongen deleted the cleanup branch May 27, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants