Skip to content

ApigeeLlm Chat Completions crashes on typed tool result values #8131

Description

@1aifanatic

Describe the bug

ApigeeLlm's Chat Completions adapter calls json.dumps directly on tool responses. A normal Python tool returning a date, datetime, Decimal, UUID, or Pydantic model therefore crashes before sending the next HTTP request. This affects both streaming and non-streaming requests.

Reproduction

Use an ApigeeLlm configured for an OpenAI-compatible Chat Completions endpoint with this tool:

import datetime
from decimal import Decimal

def get_invoice() -> dict:
    return {'due': datetime.date(2026, 12, 1), 'total': Decimal('12.50')}

When the model calls get_invoice, the result becomes a FunctionResponse successfully, but conversion to the next Chat Completions request raises TypeError: Object of type date is not JSON serializable in CompletionsHTTPClient._contents_to_messages.

Expected: send valid JSON with the date encoded as an ISO string and Decimal encoded without losing precision, consistent with ADK's typed model values. Ordinary JSON results should remain unchanged.

Environment and validation

Reproduced on main at 12aab4aaa, Python 3.12.10, Windows. A real InMemoryRunner and FunctionTool were exercised against a local HTTP server emitting OpenAI-compatible responses, for both NONE and SSE streaming. No live Apigee deployment or provider credentials were used.

This is separate from #8123, which affects the LiteLlm adapter. Apigee has its own serializer and raises rather than falling back to a Python repr. The proposed fix uses the already-installed Pydantic serializer only for values unsupported by the standard JSON encoder.

Prepared with AI assistance; reproduction and validation were executed locally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions