Repository navigation
Replies: 6 comments
|
It seems that users of adk-python are also seeking for some support to this functionality: google/adk-python#1746 |
|
Short answer: there is no supported way to inject values directly into Map<String, Object> stateDelta = Map.of(
"temp:request_id", requestId,
"temp:user_tier", userTier);
runner.runAsync(userId, sessionId, newMessage, runConfig, stateDelta);(Check the exact overload against the version you use — on current One important caveat: If you need values that must never persist in the session at all, |
|
Hi @voborl00 — following up on my answer from yesterday about propagating request-scoped attributes via the |
|
Hi @voborl00 — following up on my comment above: were you able to try it? If it solved the issue, marking it as the answer helps the next person who hits the same thing. If not, tell me what you saw and I'll take another look. |
|
Thanks @Ultroncn for following up. It's been a while since my original request so I had to put my workspace in order ;-) But looking at my old code again, I should separate two concerns. My RequestContext supplied a lazy JDBC connection provider; a database connection can usually be acquired, committed or rolled back, and closed within each tool call. The remaining framework use case is passing trusted caller data determined at the HTTP boundary—such as the authenticated principal and current tenant—to callbacks and tools for one Runner execution, while reusing the same agent and session. stateDelta does not give that guarantee. The Runner puts it into session state and attaches it to the user event. Even temp: is unsuitable for arbitrary live objects: the current InMemorySessionService handles those keys as ordinary session values in its override. My old shared-key before/after-tool workaround also cannot guarantee cleanup when a tool fails or is cancelled, and concurrent tool calls may overwrite each other’s value. Keeping the value in an HTTP-scoped holder and reading it in beforeToolCallback leaves the propagation mechanism unspecified. Tool execution is asynchronous, so a servlet ThreadLocal is not a reliable general solution. I also would not use RunConfig.customMetadata as a contract for live objects: Python ADK documents that metadata is copied to persisted events, and I would not want Java code to depend on different undocumented semantics. Could ADK Java accept opaque, transient per-execution data as a separate input to Runner.runAsync, expose it through InvocationContext and ToolContext, and propagate it to nested agent execution where appropriate? The existing InvocationContext.callbackContextData() is already an invocation-local map; seeding it before the first plugin callback might be a small implementation, although a separate public API would avoid collisions with callback internals. This data must not enter Session.state, event deltas, model input, or telemetry. On resume, the caller would supply fresh execution data rather than resurrecting an old JDBC connection. The application would remain responsible for closing its resources when the execution actually ends. Tests for repeated runs on one session, concurrent calls, errors and cancellation, and AgentTool propagation would make the scope guarantee clear. Would an API along these lines fit ADK Java’s design? |
|
Hi @voborl00 — thanks for coming back with the refined version of the question; separating Your diagnosis checks out
The Seeding
|
Uh oh!
There was an error while loading. Please reload this page.
As instances of Runner, Agent and Tool(set) are meant to be long-lived singletons, there seem to be only way how to push some variable into agent's lifecycle which is via Session object into runAsync() method. But Session also seem not to be ideal for this as it lives across many requests, so there goes my question, if is there a way how to propagate request-scoped variable into agent and better into agent's tools (ToolContext?) in order that tool used by agent will have this variable at its disposal for the given runAsync() run? Now i can only (as InvocationContext is constructed inside runAsync() method) push and then remove variable through Session with before/afterToolCallback but its more of a hack than a expected flow I suppose.
All reactions