You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Add history.clearContext and Tool.isTerminal across all SDKs (#2129)
* Add history.clearContext and Tool.isTerminal across all SDKs
Regenerates the RPC clients for the new `session.history.clearContext` method
and the `session.context_cleared` event, and adds a hand-authored `isTerminal`
tool flag to every language surface.
`isTerminal` lets a tool declare that a successful call ends the agent turn:
the runtime's tool phase halts instead of feeding the result back to the model
for another round. A failed call leaves the loop running so the model can read
the error and retry. Without it a turn-ending tool can only approximate the
behavior by returning a rejected result, which halts the loop but is
semantically wrong.
Per language:
- Node.js: `Tool.isTerminal`, `defineTool` config, both session-config
serialization sites.
- Go: `Tool.IsTerminal` with `json:"isTerminal,omitempty"`.
- Python: `Tool.is_terminal`, `define_tool` overloads, both client
serialization sites.
- Rust: `Tool::is_terminal`, skipped when false.
- Java: `ToolDefinition.isTerminal` as a record component, plus a
seven-argument convenience constructor so existing call sites keep compiling.
- .NET: `CopilotToolOptions.IsTerminal`, the `is_terminal` additional-property
key, and the wire `ToolDefinition`.
Adds serialization tests in Go, Rust and Java covering both the camelCase wire
name and omission when unset; the Java test also pins the seven-argument
constructor so the record change stays source-compatible.
* Preserve isTerminal in Java fluent copies, add Node isTerminal wire tests
Resolves the rebase onto main where both sides added an eighth tool
option: main added metadata and this branch added isTerminal.
- Java ToolDefinition now carries metadata and isTerminal as separate
record components, keeps the seven- and eight-argument convenience
constructors, and threads isTerminal through every fluent copy method
so it is no longer dropped by .metadata()/.defer()/etc.
- Adds ToolDefinition.isTerminal(boolean) so lambda-defined tools can
set it, matching the other flags.
- Adds the missing Node regression tests asserting isTerminal is
forwarded on both session.create and session.resume, and omitted when
unset.
- Applies the repo rust formatter to the new is_terminal test.
* Regenerate clearContext bindings for the tightened runtime contract
Mirrors github/copilot-agent-runtime#14002 after review:
- `HistoryClearContextRequest.prompt` is now required. A cleared window
holding only system and developer messages is not a conversation a model
can answer, so every clear seeds the window it creates.
- `HistoryClearContextResult` loses the `cleared` discriminator. The RPC now
rejects the cases it was meant to describe - a remote session, or a call
made while no tool call is in flight - so there is one error channel
instead of a success flag plus an error channel.
- `ContextClearedData.prependMessages` is gone. It had no producer, and it
was a permanent commitment on a durable event for a code path nothing
exercised.
Regenerated with `scripts/codegen`; only the clear-context hunks are taken,
so unrelated schema drift stays out of this PR.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Close the two remaining reviewer findings on isTerminal
The automated reviewer raised two suppressed findings against the new
Tool.isTerminal field. Both were accurate.
Rust: Tool has a hand-written Debug impl that enumerates every other
serializable field, so is_terminal was silently missing from its output
and a terminal tool debug-printed identically to a plain one. Add the
field in declaration order, plus a test that fails if the hand-written
impl drifts again.
Python: dotnet, go, java, nodejs and rust all assert that isTerminal
reaches the wire on both the session.create and session.resume paths and
is omitted at its default. Python was the only SDK without that
coverage. Add the test, mirroring the adjacent tool-metadata test.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix @SInCE on the new Java isTerminal setter
ToolDefinition.isTerminal(boolean) is introduced by this PR but was
tagged @SInCE 1.0.7, a version released long ago in which the method did
not exist, so the generated javadoc would misstate its availability.
1.0.11 is the current unreleased version: the pom is at
1.0.10-preview.3-SNAPSHOT, and the eight java/src/main files carrying
@SInCE 1.0.11 include ToolDefinition.createOverride in this same file.
This was the only @SInCE tag the PR added.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Expose isTerminal through Java tool annotations
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Test .NET terminal tools on session requests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Cover terminal tool runtime behavior end to end
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Document context clearing and terminal tools
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Normalize clear context snapshot formatting
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: examon <examon@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
Use `session.history.clearContext` when a host needs to replace the current conversation context without replacing the session. Typical uses include handoffs and host-managed context lifecycle policies.
4
+
5
+
Context clearing is different from creating a new session: it preserves the session identity, system and developer messages, configuration, and event log while removing the model-facing conversation.
6
+
7
+
> [!IMPORTANT]
8
+
> `clearContext` is a tool-handler primitive. The runtime rejects calls made without a tool call in flight, calls with an empty seed prompt, and calls on remote sessions.
9
+
10
+
## Define a context-clearing tool
11
+
12
+
A successful context-clearing tool should be terminal. Otherwise, the agent loop may make another model call against the newly cleared window before starting the seeded turn.
The required `prompt` becomes the first user message in the fresh context. A successful clear emits `session.context_cleared` with the number of removed messages and the initial message.
41
+
42
+
## Terminal-tool behavior
43
+
44
+
`isTerminal` ends the current agent turn only when the tool succeeds. A failure, denial, rejection, timeout, or input-validation error remains visible to the model so it can recover or retry.
45
+
46
+
The option follows each language's naming conventions:
47
+
48
+
| SDK | Tool option |
49
+
|---|---|
50
+
| Node.js |`isTerminal`|
51
+
| Python |`is_terminal`|
52
+
| Go |`IsTerminal`|
53
+
| .NET |`CopilotToolOptions.IsTerminal`|
54
+
| Java |`ToolDefinition.isTerminal(true)` or `@CopilotTool(isTerminal = true)`|
55
+
| Rust |`with_is_terminal(true)`|
56
+
57
+
Use terminality only for tools whose successful completion should end the turn. Ordinary tools should leave it unset.
if(toolOptionsis not null&&(toolOptions.OverridesBuiltInTool||toolOptions.SkipPermission||toolOptions.Deferis not null||toolOptions.Metadatais not null))
97
+
if(toolOptionsis not null&&(toolOptions.OverridesBuiltInTool||toolOptions.SkipPermission||toolOptions.IsTerminal||toolOptions.Deferis not null||toolOptions.Metadatais not null))
0 commit comments