Add searchMessages() method to query inside session history
Summary
Implement a searchMessages() method across all SDK languages to enable in-session message filtering and search.
Problem
Users currently has to manually filter through all session events to find specific messages. This is cumbersome for:
- Debugging long conversations
- Finding specific agent responses
- Building audit/search features on top of the SDK
Proposed Solution
Add async searchMessages(query, options) method that:
- Accepts string or regex patterns
- Filters by event type (optional)
- Supports case-sensitive/insensitive search
- Returns filtered SessionEvent[] matching criteria
Example Usage
// TypeScript
const results = await session.searchMessages("authentication");
const assistantMsgs = await session.searchMessages("deploy", {
eventType: "assistant.message"
});
I'd like to work on this. π
I've opened github/copilot-sdk#2378 with a first implementation for the Node.js/TypeScript SDK β an async searchMessages(query, options?) on CopilotSession supporting string/RegExp queries, optional eventType filtering, and case-sensitivity, with unit tests.
I understand from CONTRIBUTING that feature work should be aligned with the team first and kept in sync across all supported languages, so I'm treating that PR as a concrete starting point for the discussion rather than a finished proposal. If you're open to this feature, I'm happy to extend it to the other SDKs (Python, Go, .NET, Java, Rust) and adjust the API shape/semantics to match your preferences.
I opened draft PR #2380 with an alternative cross-language implementation for Node.js, Python, Go, .NET, and Java. It intentionally overlaps with #2378, but proposes a narrower contract: search only persisted user.message and assistant.message content instead of recursively searching every string field in arbitrary event data. Also @maintainers could you please advise which search semantics and cross-language API shape you prefer?
I am happy to coordinate with @Anvith433 and revise or consolidate the work based on maintainer direction.
Hey @Navanit-git, thanks for the heads up, and for pinging me instead of just going ahead on your own.
Happy to fold my work into yours. Java's the language I actually know well, so I'd like to take the Java part of #2380 - the implementation and the tests.
Honestly your version makes more sense than mine. In #2378 I searched every
string field, but just searching user.message and assistant.message is a
lot cleaner and easier to reason about. So no attachment to my approach, I'm
good with whatever you and the maintainers decide on.
Just let me know what signature you want for the Java method and I'll match it. And I'm fine closing #2378 once this is sorted.
Thanks @Anvith433 I appreciate the collaboration. Letβs work together to address this issue once a maintainer confirms if any changes is required or need another approach too.
@Navanit-git I would be very happy to work with you and solve this issue , thank you.
Thanks for the proposal and the PRs. As noted on #2380, we don't plan to add a dedicated search API, since it wouldn't do more than retrieving the session's events and filtering them with a predicate, which is easy to tailor to each app. For example, in Node.js: const hits = (await session.getEvents()).filter((e) => e.type === "assistant.message" && /deploy/i.test(e.data.content)); β the equivalents are get_events() in Python and Rust, GetEventsAsync() in .NET, GetEvents(ctx) in Go and getMessages() in Java. Closing as answered β feel free to reopen if this doesn't cover your case.
Triaged as part of a Copilot SDK backlog review, with help from GitHub Copilot.