Add opaque metadata passthrough to SDK tool definitions#1864
Add opaque metadata passthrough to SDK tool definitions#1864belaltaher8 wants to merge 8 commits into
metadata passthrough to SDK tool definitions#1864Conversation
68c607d to
6fdc349
Compare
metadata passthrough to SDK tool definitions
There was a problem hiding this comment.
Pull request overview
Adds an optional, opaque metadata bag to tool definitions across the multi-language SDKs and forwards it verbatim over session.create / session.resume, enabling hosts to attach namespaced, runtime-recognized (but SDK-opaque) attributes without expanding the typed contract.
Changes:
- Add
metadatato tool definition types/builders (Rust/Go/Node/Python/.NET/Java) with “omit when unset” behavior where applicable. - Wire
metadatathrough session create/resume payload construction (Node + Python shown here; others rely on serialization of the definition type). - Add/extend unit tests to validate serialization and omission semantics; update Java annotation-processor fixtures for the new constructor arity.
Show a summary per file
| File | Description |
|---|---|
| rust/src/types.rs | Add Tool.metadata, builder, Debug output, and serialization test. |
| python/copilot/tools.py | Add Tool.metadata + define_tool(..., metadata=...) passthrough. |
| python/copilot/client.py | Include metadata when building tool definitions for create/resume RPCs. |
| python/test_client.py | Add test asserting metadata forwarded on create/resume and omitted when unset. |
| nodejs/src/types.ts | Extend Tool / defineTool types to include optional metadata. |
| nodejs/src/client.ts | Forward tool.metadata into session.create / session.resume payloads. |
| nodejs/test/client.test.ts | Add tests for forwarding and omission of metadata. |
| go/types.go | Add Tool.Metadata with omitempty JSON tag. |
| go/client_test.go | Add serialization tests for tool metadata presence/omission. |
| dotnet/src/CopilotTool.cs | Add MetadataKey + option plumbing into AITool.AdditionalProperties. |
| dotnet/src/Client.cs | Include metadata in internal wire ToolDefinition built from AI function declarations. |
| dotnet/test/Unit/CopilotToolTests.cs | Add unit tests ensuring metadata is set/omitted in additional properties. |
| java/src/main/java/com/github/copilot/rpc/ToolDefinition.java | Add metadata record component + factories + fluent modifier. |
| java/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java | Emit null metadata argument in generated ToolDefinition(...) calls. |
| java/src/test/java/com/github/copilot/ToolDefinitionTest.java | Add serialization tests for metadata presence/omission. |
| java/src/test/java/com/github/copilot/rpc/fixtures/StaticTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/StaticInvocationTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/SimpleTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/OverrideTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/OptionalParamTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/MultiReturnTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/InvocationAwareTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/DefaultValueTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/DateTimeTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/ArgCoercionTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/e2e/ErgonomicTestTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
Review details
- Files reviewed: 26/26 changed files
- Comments generated: 1
- Review effort level: Low
Add an optional, opaque `metadata` bag to tool definitions across all SDK languages and forward it verbatim over the session.create/resume RPC. This lets hosts attach namespaced metadata to tools without expanding the typed public contract; the runtime may recognize specific keys to inform host-specific behavior. Unknown keys are round-tripped untouched. Languages: nodejs (Tool.metadata + defineTool), python (Tool.metadata + define_tool), go (Tool.Metadata), rust (Tool.metadata + with_metadata), java (ToolDefinition.metadata + createWithMetadata), dotnet (CopilotToolOptions.Metadata + wire ToolDefinition.Metadata). Tests added per language for wire/serialization forwarding and omission when unset. Co-authored-by: Copilot <[email protected]>
6fdc349 to
0d575bc
Compare
| /// forwards them verbatim to the runtime, which may recognize specific | ||
| /// keys to inform host-specific behavior. Unknown keys are preserved and | ||
| /// round-tripped untouched. | ||
| #[serde(default, skip_serializing_if = "HashMap::is_empty")] |
There was a problem hiding this comment.
I think skip_serializing_if = "HashMap::is_empty" might be inconsistent with the other SDKs, which would send empty dictionaries. Is there any situation where it would be important to (or not to) send an empty dictionary? My guess is it's semantically equivalent but just want to check.
There was a problem hiding this comment.
i think we're fine here. An empty metadata object carries no keys, so it decodes to absent in the other languages too. I believe that Go and Rust would omitempty. And the other SDKs default to null/undefined which omits
it'd be {} if someone passes an empty bag
- dotnet: change Metadata value type to IDictionary<string, JsonNode?> for
NativeAOT-safe serialization (CopilotToolOptions + wire ToolDefinition,
FromAIFunction cast, unit test); drop redundant [JsonPropertyName("metadata")]
since the Web camelCase policy already maps it; remove the <remarks> block
from the Metadata property.
- Reword metadata doc comments across nodejs/python/go/rust/java to describe
the bag opaquely without the SDK-vs-runtime/CLI distinction.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
…-passthrough # Conflicts: # python/test_client.py
edburns
left a comment
There was a problem hiding this comment.
Please see this comment.
Address Java SME feedback so annotation-based tools reach parity with the programmatic API and existing constructor call sites keep compiling. - ToolDefinition: add a backward-compatible 7-arg constructor delegating to the canonical 8-arg with metadata=null. - CopilotTool: add metadata() plus nested MetadataEntry/MetadataValue/ MetadataFlag annotations (@target({})) with a shallow bool|str|flag-map representation, documenting the programmatic API for richer values. - CopilotToolProcessor: generate the metadata constructor argument (Map.<String, Object>of(...) with an explicit type witness) instead of a hardcoded null; null when no metadata is present. - Tests: processor generation cases (nested flags, absent, combined flags), ToolDefinition 7-arg/.metadata(...) copy/flag-chaining cases, and a fromObject metadata assertion; extend the SimpleTools fixture pair to emit a safeForTelemetry metadata map. - ADR-005: update the generated snippet to the 8-arg shape and document the @copilotTool(metadata = ...) syntax and emitted shape. Note: mvn verify / spotless:apply not run locally (no JDK/Maven in the dev environment); relies on PR CI. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
Reflow javadoc and wrap annotation/constructor args per the Eclipse formatter (mvn spotless:apply). No behavioral change. Verified locally: mvn spotless:check clean; ToolDefinitionTest (8), ToolDefinitionFromObjectTest (31), CopilotToolProcessorTest (37) all pass on JDK 26. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
Co-authored-by: Copilot <[email protected]> Copilot-Session: ab2c14cd-d2e1-4524-a6dc-e9c10899343c
edburns
left a comment
There was a problem hiding this comment.
Please see #1864 (comment)
Do that and I'll give the green checkmark. Thanks.
test: assert null metadata arg in generated tool definition
Add an optional
_metadatabag to theTooldefinition (anddefineTool) and forward it verbatim over the session.create/resume RPC. This lets hosts attach namespaced, opaque metadata to tools without expanding the typed public contract; unknown keys are round-tripped untouched.