Merged
Conversation
PiperOrigin-RevId: 862232259
This is going to be a useful feature for rewind PiperOrigin-RevId: 862232441
PiperOrigin-RevId: 862235526
This CL integrates event compaction configuration into the InvocationContext, allowing agent to access the configs during execution. PiperOrigin-RevId: 862366865
PiperOrigin-RevId: 862713740
PiperOrigin-RevId: 862788975
PiperOrigin-RevId: 862818185
PiperOrigin-RevId: 863081612
…nfig This interface change allows intra-invocation compaction with configurable trigger threshold and number of events to be preserved from being compacted. PiperOrigin-RevId: 863086157
PiperOrigin-RevId: 864223068
PiperOrigin-RevId: 864224090
…rationtoolset PiperOrigin-RevId: 864263802
PiperOrigin-RevId: 864312028
reducing cyclical dependencies would help create something akin to "adk-light" PiperOrigin-RevId: 864316690
The `saveAndReloadArtifact()` enables a save without a second i/o call just to get the full file path. PiperOrigin-RevId: 864659692
… tail of the event stream Provide a way to manage the size of an event stream Specifically, it: * Keeps the retentionSize most recent events raw. * Compacts all events that never compacted and older than the retained tail, including the most recent compaction events, into a new summary event. * Appends this new summary event to the end of the event stream. PiperOrigin-RevId: 864748009
…and consistency
This CL refactors parts of the ADK codebase to improve null safety and consistency. The main changes include:
1. **`BaseAgent`**:
* `beforeAgentCallback` and `afterAgentCallback` fields and their accessors now use `ImmutableList` (defaulting to empty) instead of `Optional<List>`.
* `findAgent` and `findSubAgent` now return `Optional<BaseAgent>`, with `findSubAgent` being reimplemented using Java Streams.
2. **`BaseAgentConfig`**: Getters for `subAgents`, `beforeAgentCallbacks`, and `afterAgentCallbacks` now return an empty list if the underlying field is null.
3. **`CallbackUtil`**: `getBeforeAgentCallbacks` and `getAfterAgentCallbacks` return `ImmutableList.of()` instead of `null` for null inputs.
4. **`LlmAgent`**: The `codeExecutor()` method now returns `Optional<BaseCodeExecutor>`.
These changes necessitate updates in `BaseLlmFlow`, `CodeExecution`, and `Runner` to handle the new `Optional` return types.
PiperOrigin-RevId: 864883202
PiperOrigin-RevId: 864938809
PiperOrigin-RevId: 864976785
PiperOrigin-RevId: 865067193
PiperOrigin-RevId: 865089943
…ion responses are merged
PiperOrigin-RevId: 865462678
This change ensures the trace context is propagated across asynchronous boundaries for LLM and Tool calls. PiperOrigin-RevId: 865572112
PiperOrigin-RevId: 865975883
PiperOrigin-RevId: 866029385
…Python ADK This change introduces ContextCacheConfig, a configuration class for enabling and controlling context caching across all agents within an ADK application. The App class is updated to include an optional ContextCacheConfig, allowing applications to specify caching parameters such as cache intervals, TTL, and minimum token thresholds for caching. PiperOrigin-RevId: 866030713
This allows callbacks and tools to know which event triggered them. This is useful in telemetry and tracing. PiperOrigin-RevId: 866050613
PiperOrigin-RevId: 866059790
Wonder if we can downgrade those two info() level loggings. They make viewing information from our debugger CLI very difficult. PiperOrigin-RevId: 866158204
A single LiveServerMessage is now converted to a series of LlmResponse messages each corresponding to a different part of the LiveServerMessage, notably the UsageMetadata field is now converted to a GenerateResponseUsageMetadata and emitted downstream. PiperOrigin-RevId: 867516050
PiperOrigin-RevId: 868014417
…istory reinstating the fix in google#682 which was later reverted in google#827 PiperOrigin-RevId: 868043103
PiperOrigin-RevId: 868164137
PiperOrigin-RevId: 868170491
PiperOrigin-RevId: 868224060
PiperOrigin-RevId: 868235383
This update should make the java tracing consistent with Python ADK:
1. **`BaseAgent.java`**:
* The `runAsync` and `runLive` methods have been modified to create the `InvocationContext` before starting the tracing span.
* The span name for agent invocations has been changed from `"agent_run [<agent name>]"` to `"invoke_agent <agent name>"`.
* A new `Tracing.traceAgentInvocation` method is now called to add initial tracing attributes for the agent invocation.
* In `runLive`, the `runLiveImpl` execution is now wrapped with calls to `beforeAgentCallback` and `afterAgentCallback` to ensure proper tracing of these lifecycle events.
2. **`Tracing.java`**:
* The OpenTelemetry tracer name has been updated from `"com.google.adk"` to `"gcp.vertex.agent"`.
* A new `traceAgentInvocation` method has been added to set standard attributes for agent invocation spans, including `gen_ai.operation.name`, `gen_ai.agent.description`, `gen_ai.agent.name`, and `gen_ai.conversation.id`.
* Attribute keys used in `traceToolCall`, `traceToolResponse`, `traceCallLlm`, and `traceSendData` have been updated to use the `"gcp.vertex.agent."` prefix instead of `"adk."` or `"com.google.adk"`.
* The serialization of message content (like tool call arguments, tool responses, and data) is now guarded by the `CAPTURE_MESSAGE_CONTENT_IN_SPANS` flag. When disabled, empty JSON objects are recorded instead.
* `traceToolResponse` now includes logic to extract and trace the `tool_call.id` and the tool response content from `FunctionResponse` objects.
* `traceCallLlm` now captures additional LLM request and response details, such as `gen_ai.request.top_p`, `gen_ai.request.max_tokens`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.response.finish_reasons`.
PiperOrigin-RevId: 868299966
This change introduces ContextCacheConfig to the InvocationContext and Runner classes, allowing context cache settings to be configured per invocation. PiperOrigin-RevId: 868315679
Python and Vertex Session Store moved to use endOfAgent, so we should use that as well. PiperOrigin-RevId: 868587270
PiperOrigin-RevId: 868617839
This testing found an improvement in how span propogation works in Function Calling. I would like to do a significant refactoring to cleanup all of the sprinkled tracing code. This step is necessary to confirm proper behavior before the refactor. PiperOrigin-RevId: 868623517
1. **Extracting Common Run Logic:** A new private method `run` is introduced to encapsulate the common setup and execution flow shared by both `runAsync` and `runLive`. This includes creating the `InvocationContext`, setting up tracing, and handling before/after callbacks.
2. **Reducing Duplication:** Both `runAsync` and `runLive` now call this new `run` method, passing their specific implementation (`runAsyncImpl` or `runLiveImpl`) as a function. This eliminates a significant amount of duplicated code.
3. **Minor Cleanups:**
* The `createInvocationContext` method now uses `parentContext.branch().filter(...).ifPresent(...)` for a more concise optional handling.
* An unnecessary `agentCallbacks == null` check is removed from `callCallback`, as the list should not be null.
PiperOrigin-RevId: 868646905
…cation_id', 'agent', and 'session' fields PiperOrigin-RevId: 868688936
PiperOrigin-RevId: 868735240
PiperOrigin-RevId: 868944170
PiperOrigin-RevId: 869194554
Map<String, Integer> now matches with Vertex AI Session API and the python artifactDelta implementation. The new implementation unblocks rewind functionality.
Background:
- Artifact service stores artifacts with a key like `{app}_{user}_{sessionId}_{file}_{version}`
- Session service has the app, user, session id. It saves EventAction with an economic `[file] : [version]` map. The Python ADK always had it this way, and somehow Java diverged.
PiperOrigin-RevId: 869350765
The ADK Python code has pause/resume/rewind functionality. It's going to be some time before ADK Java gets it. For now, it's worth cleaning up the half-baked feature. PiperOrigin-RevId: 869384320
PiperOrigin-RevId: 869400120
PiperOrigin-RevId: 869686128
PiperOrigin-RevId: 869687403
PiperOrigin-RevId: 869697412
PiperOrigin-RevId: 869700933
PiperOrigin-RevId: 869704217
Refactor the tracing implementation within the Google ADK to simplify how OpenTelemetry spans are managed, especially within RxJava streams.
The key changes include:
1. **Introducing `Tracing.TracerProvider`**: A new set of RxJava transformers (`FlowableTransformer`, `SingleTransformer`, `MaybeTransformer`, `CompletableTransformer`) is added in `Tracing.java`. These transformers, created via `Tracing.trace()` methods, handle the lifecycle of OpenTelemetry spans, including span creation, making the span current, and ending the span upon stream completion or error.
2. **Simplifying Tracing Calls**: Instead of manually creating and managing spans with `Tracer`, `Span`, and `Scope`, various parts of the codebase now use the `.compose(Tracing.trace(...))` operator on RxJava streams. This is applied in:
* `BaseAgent.java`: For agent invocations using `Tracing.traceAgent`.
* `BaseLlmFlow.java`: For LLM calls (`call_llm`) and sending data (`send_data`).
* `Functions.java`: For tool responses and tool calls.
* `Runner.java`: For overall invocation spans in `runAsync` and `runLive`.
3. **Centralized Attribute Setting**: Helper methods like `getValidCurrentSpan`, `setInvocationAttributes`, `setToolExecutionAttributes`, and `setJsonAttribute` are added to `Tracing.java` to encapsulate and standardize how attributes are set on spans, including handling JSON serialization and checks for valid spans.
These changes aim to reduce tracing-related boilerplate, improve consistency, and make the tracing logic more robust by tying span lifetimes to RxJava stream lifecycles.
PiperOrigin-RevId: 869714739
PiperOrigin-RevId: 869797377
PiperOrigin-RevId: 871158148
…ption support to new structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.