fix(agentengine): support Gemini Enterprise AgentSpace streams#777
fix(agentengine): support Gemini Enterprise AgentSpace streams#777jankrynauw wants to merge 6 commits into
Conversation
kdroste-google
left a comment
There was a problem hiding this comment.
Hi, @jankrynauw,
Thank you for your contribution!!
I think we should not merge those two methods: stream_query and streaming_agent_run_with_events - the separate controllers/method and internal/models should be clearer and more maintainable (no internal "if" and conditionally empty fields).
What do you think?
|
Hi @kdroste-google, I had that exact same thought this weekend, let me implement the change and get back to you. My initial thought is to keep the logic within the agentengine server and simply split the logic into its own handler so that the current: // listStreamHandlers returnes a list of handlers for streaming methods
func listStreamHandlers(config *launcher.Config, agentEngineID string) []method.MethodHandler {
return []method.MethodHandler{
method.NewStreamQueryHandler(config, agentEngineID, "async_stream_query", "async_stream"),
method.NewStreamQueryHandler(config, agentEngineID, "streaming_agent_run_with_events", "stream"),
}
}effectively becomes // listStreamHandlers returnes a list of handlers for streaming methods
func listStreamHandlers(config *launcher.Config, agentEngineID string) []method.MethodHandler {
return []method.MethodHandler{
method.NewStreamQueryHandler(config, agentEngineID, "async_stream_query", "async_stream"),
method.NewStreamingAgentRunWithEventsHandler(config, agentEngineID, "streaming_agent_run_with_events", "stream"),
}
} |
…dler runner configuration.
…se-sessions-to-adk
- The Go test check was failing in TestDebugTelemetryGetSpansBySessionID because the test asserted a fixed ordering for returned spans. In practice, the debug telemetry store can return the same set of spans in a different order depending on span/export timing, especially when spans are created and ended very close together. - This change keeps the production behavior unchanged and updates the tests to compare spans as a stable sorted set before diffing. The comparison still checks the span names, relevant attributes, and logs, but no longer treats incidental retrieval order as part of the contract.
jankrynauw
left a comment
There was a problem hiding this comment.
@kdroste-google I could also remove all references to AgentSpace - and instead use Gemini Enterprise?





Problem:
Gemini Enterprise / AgentSpace invokes ADK agents on Agent Engine using the
streaming_agent_run_with_eventsmethod. ADK Go did not fully match the request and response contract used by the Python ADK Agent Engine implementation.Observed issues:
input.request_json.session_idis a Gemini Enterprise / Discovery Engine session resource, not a backend ADK session ID.VertexAISessionServicefails because user-provided session IDs are not supported.Solution:
This PR adds Gemini Enterprise / AgentSpace compatibility for
streaming_agent_run_with_eventsin ADK Go:Registers
streaming_agent_run_with_eventsas an Agent Engine stream handler.Decodes the wrapped
input.request_jsonpayload.Treats the first Gemini Enterprise session resource as a bootstrap identifier.
Checks whether the incoming
session_idis already a backend ADK session ID.Creates a generated backend ADK session when the incoming
session_idis not already a backend ADK session.Returns the generated backend ADK session ID in the response envelope so Gemini Enterprise can use it on later turns.
Reuses the returned backend ADK session ID on subsequent Gemini Enterprise requests.
Emits the Python ADK-style response envelope for
streaming_agent_run_with_events:{ "events": [], "artifacts": [], "session_id": "..." }Uses non-SSE run mode for
streaming_agent_run_with_eventsto avoid Gemini Enterprise rendering both partial and final text as duplicate answer content.Leaves existing
async_stream_querybehavior unchanged.Testing Plan
Unit Tests:
Passed locally:
Coverage added for:
input.request_jsonstreaming_agent_run_with_eventsstreaming_agent_run_with_eventsuses non-SSE mode to avoid duplicate Gemini Enterprise response textVertexAISessionServicebehavior that rejects caller-provided session IDs on createManual End-to-End (E2E) Tests:
Manually tested with a deployed ADK Go agent invoked from Gemini Enterprise / AgentSpace.
Verified:
streaming_agent_run_with_events.input.request_json.session_id.streaming_agent_run_with_events.Checklist
Additional context
This behavior was compared against the Vertex AI Python SDK
AdkApp.streaming_agent_run_with_eventsimplementation. The Go implementation now follows the same high-level contract for Gemini Enterprise / AgentSpace invocation: wrapped request input, generated backend ADK session IDs returned in the response envelope, backend session IDs reused on later turns, and response events wrapped in an AgentSpace-compatible envelope.