Skip to content

Add per-call tool context provider to Python SDK#1693

Open
idryzhov wants to merge 1 commit into
github:mainfrom
idryzhov:idryzhov/python-tool-context-provider
Open

Add per-call tool context provider to Python SDK#1693
idryzhov wants to merge 1 commit into
github:mainfrom
idryzhov:idryzhov/python-tool-context-provider

Conversation

@idryzhov

Copy link
Copy Markdown
Contributor

Introduce an optional on_provide_tool_context callback on create_session/resume_session. When registered, the SDK invokes it once per tool call with the ToolInvocation (awaiting coroutine results) and assigns the return value to the new ToolInvocation.context field before the handler runs. This lets apps inject per-call application context (services, request state) into custom tool handlers without routing it through model-facing tool arguments. The context is filled in locally and is never serialized over the wire.

Introduce an optional `on_provide_tool_context` callback on
`create_session`/`resume_session`. When registered, the SDK invokes it
once per tool call with the `ToolInvocation` (awaiting coroutine results)
and assigns the return value to the new `ToolInvocation.context` field
before the handler runs. This lets apps inject per-call application context
(services, request state) into custom tool handlers without routing it
through model-facing tool arguments. The context is filled in locally and is
never serialized over the wire.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 22:40
@idryzhov idryzhov requested a review from a team as a code owner June 16, 2026 22:40
@idryzhov idryzhov marked this pull request as draft June 16, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@idryzhov idryzhov marked this pull request as ready for review June 17, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants