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
{{ message }}
Repository navigation
[dotnet-port-api] agent-as-tool: session propagation and argument customization #1139
Parity gap surfaced comparing tool/agenttool against .NET/Python.
Gap
agenttool hardcodes a single query string argument and runs the sub-agent with an independent context, returning only resp.String(). It cannot:
Propagate the parent session to the sub-agent (so a sub-agent-as-tool starts stateless every call).
Customize the argument name/description.
Note: the tool name/description defaults and the query arg name already match .NET (AgentExtensions.cs), so those are intentionally aligned — only session propagation and arg customization are missing.
.NET AsAIFunction(this AIAgent, options, session) accepts a session (AgentExtensions.cs).
Proposed shape (needs maintainer input)
Add optional config to the agenttool constructor, e.g.:
agenttool.New(a, agenttool.Config{
ArgName: "task", // default "query" (matches .NET)ArgDescription: "...",
PropagateSession: true, // thread the caller's *agent.Session into the sub-run
})
Open questions:
How to obtain the caller session at Call time — thread it via context, or capture from the invoking run? (Go tool Call(ctx, argsJSON) has no session param today.)
Should session propagation be opt-in (default off, matching a stateless tool) or default on (matching Python's common usage)?
Whether to also surface sub-agent approval/user-input requests (Python raises UserInputRequiredException; .NET returns .Text — Go currently matches .NET).
Filing issue-first per CONTRIBUTING (new public API). Happy to implement once the direction is settled.
Investigated the session-propagation half. It needs new plumbing, not just an agenttool change:
The agent is placed in the run context (agent.goctx = context.WithValue(ctx, agentKey{}, a)), but the session is only passed via run options (agent.WithSession), and toolautocall reads it from those options.
A tool.Tool.Call(ctx, args) receives only ctx and the JSON args — not the options, so there is no way for agenttool.Call to reach the caller's session today.
So propagating the session cleanly requires two coordinated changes: (1) expose the run session on the context (e.g. a public SessionFromContext + having toolautocall inject it into the ctx it passes to Call), and (2) have agenttool read it and forward WithSession to the sub-run. That's a cross-cutting change to the tool-calling contract, so it's worth settling the mechanism here before implementing. The argument-customization half is already done in #1157.
Activity
PratikDhanave commentedon Sep 23, 2026
Investigated the session-propagation half. It needs new plumbing, not just an
agenttoolchange:agent.goctx = context.WithValue(ctx, agentKey{}, a)), but the session is only passed via run options (agent.WithSession), andtoolautocallreads it from those options.tool.Tool.Call(ctx, args)receives onlyctxand the JSON args — not the options, so there is no way foragenttool.Callto reach the caller's session today.So propagating the session cleanly requires two coordinated changes: (1) expose the run session on the context (e.g. a public
SessionFromContext+ havingtoolautocallinject it into thectxit passes toCall), and (2) haveagenttoolread it and forwardWithSessionto the sub-run. That's a cross-cutting change to the tool-calling contract, so it's worth settling the mechanism here before implementing. The argument-customization half is already done in #1157.