Skip to content

Commit a348a30

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add sessionId() and events() to ReadOnlyContext
When using callbacks, developers should be able to access the session ID and events. PiperOrigin-RevId: 782105841
1 parent b862ad4 commit a348a30

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

core/src/main/java/com/google/adk/agents/ReadonlyContext.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package com.google.adk.agents;
1818

19+
import com.google.adk.events.Event;
20+
import com.google.common.collect.ImmutableList;
1921
import com.google.common.collect.ImmutableMap;
2022
import com.google.genai.types.Content;
23+
import java.util.List;
2124
import java.util.Map;
2225
import java.util.Optional;
2326

@@ -50,6 +53,21 @@ public String agentName() {
5053
return invocationContext.agent().name();
5154
}
5255

56+
/** Returns the session ID. */
57+
public String sessionId() {
58+
return invocationContext.session().id();
59+
}
60+
61+
/**
62+
* Returns a read-only view of the events of the current session.
63+
*
64+
* <p>This is a shallow copy and if the underlying values of the list are modified, the read-only
65+
* view will also be modified.
66+
*/
67+
public ImmutableList<Event> events() {
68+
return ImmutableList.copyOf(invocationContext.session().events());
69+
}
70+
5371
/**
5472
* Returns a read-only view of the state of the current session.
5573
*

0 commit comments

Comments
 (0)