mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
fix(a2a_endpoints): use try/finally so deferred spend log fires even when guardrail blocks with 422
This commit is contained in:
parent
138bcc8051
commit
801d7713f4
1 changed files with 15 additions and 5 deletions
|
|
@ -468,6 +468,9 @@ async def invoke_agent_a2a( # noqa: PLR0915
|
|||
id=request_id,
|
||||
params=MessageSendParams(**params),
|
||||
)
|
||||
# Defer spend-log until after post_call_success_hook so guardrail
|
||||
# results written by the unified_guardrail hook are captured.
|
||||
logging_obj._defer_async_logging = True # type: ignore[union-attr]
|
||||
response = await asend_message(
|
||||
request=a2a_request,
|
||||
api_base=agent_url,
|
||||
|
|
@ -479,11 +482,18 @@ async def invoke_agent_a2a( # noqa: PLR0915
|
|||
agent_extra_headers=agent_extra_headers,
|
||||
)
|
||||
|
||||
response = await proxy_logging_obj.post_call_success_hook(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
data=data,
|
||||
response=response,
|
||||
)
|
||||
try:
|
||||
response = await proxy_logging_obj.post_call_success_hook(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
data=data,
|
||||
response=response,
|
||||
)
|
||||
finally:
|
||||
_enqueue_fn = getattr(logging_obj, "_enqueue_deferred_logging", None)
|
||||
if _enqueue_fn is not None:
|
||||
logging_obj._enqueue_deferred_logging = None # type: ignore[union-attr]
|
||||
_enqueue_fn()
|
||||
|
||||
return JSONResponse(
|
||||
content=(
|
||||
response.model_dump(mode="json", exclude_none=True) # type: ignore
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue