Skip to content

Decide Foundry client support for sticky hosted sessions and conversation creation #111

Closed

Description

@shibayan

Summary

Two Foundry client capabilities exist in .NET and Python but not in TypeScript. Both add public API or serialized session state, so this issue is a decision gate rather than implementation authorization.

  1. Sticky hosted agent_session_id: capture the hosted sandbox ID returned by the service and send it on later requests.
  2. Server-side conversation creation: create a Foundry conversation up front and return a session using its conv_... service ID.

Go defines neither capability.

Maintainer decision gate

Implementation must not start until each track has exactly one recorded outcome and rationale.

A. Sticky hosted session ID

  • Approve for implementation; or
  • Defer/reject and document the raw-passthrough workaround.

B. Conversation creation

  • Approve for implementation; or
  • Defer/reject and document the direct-SDK workaround.

If both are approved, implement them in separate PRs to follow the repository's one-concern-per-PR rule.

A. Implementation contract if approved

  • Capture a non-empty returned agent_session_id in awaited and streamed paths under a Foundry-owned AgentSession.state key.
  • Re-send it on every later service request, including another provider/tool round in the same run, not only the next run.
  • Preserve it through session JSON serialization/restoration.
  • Sessions never share sticky IDs, and a run without a session does not mutate client/global state.
  • Define explicit per-call versus session-pinned precedence. Different non-empty values fail before sending; the same value is allowed.
  • Once observed, the ID remains captured if later agent processing fails or the consumer disposes the stream.
  • Caller-owned options are not mutated.
  • README/TSDoc distinguish hosted sandbox ID from serviceSessionId/conversation ID and explain lifecycle ownership.

B. Implementation contract if approved

  • Call the Foundry conversation-create endpoint once and return an AgentSession whose serviceSessionId is the returned conv_... ID.
  • An optional local sessionId does not replace the provider conversation ID.
  • Supported construction paths work when a conversations client is available; otherwise fail locally with a clear configuration error.
  • Cancellation and provider failures use the package's normal error boundary.
  • The API does not imply automatic provider-conversation deletion or lifecycle management.
  • Exported API includes TSDoc, a README example, CHANGELOG entry, and public-api-change review.

Activity

  1. added
    foundryUsage: [Issues, PRs], Target: Microsoft Foundry integrations
    on Aug 29, 2026
  2. added theissue type on Aug 29, 2026
  3. self-assigned this
    on Aug 29, 2026
  4. changed the title [-]Add Foundry client support for sticky hosted agent session IDs and conversation creation[/-] [+]Decide Foundry client support for sticky hosted sessions and conversation creation[/+] on Aug 30, 2026
  5. shibayan commented on Sep 1, 2026

    @shibayan
    MemberAuthor

    Reference verification

    Both tracks were checked against the pinned references (microsoft/agent-framework edfe115ea,
    microsoft/agent-framework-go 6aabdc7). Go defines neither, as the issue states.

    A. Sticky hosted session id — implemented in both .NET and Python

    • .NET stores it in AgentSession.StateBag under
      FoundryAgentSessionExtensions.FoundryHostedAgentSessionIdKey, and
      FoundryChatOptionsExtensions.WithFoundryHostedAgentSessionId puts agent_session_id on the
      Responses body. FoundryAgent.CreateFoundryHostedAgentSessionAsync optionally pins an existing id.
    • Python captures it from the response (_extract_foundry_hosted_agent_session_id), stores it
      under FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY, and re-injects it into extra_body.

    Python's placement is the notable part. It writes the id to both the session and the current
    run's options, in _update_function_invocation_continuation_state, with this reason:

    Persist the ID for later runs and inject it into the current options because function invocation
    can make another service call before the agent prepares a new run context.

    That is precisely the acceptance criterion in this issue about re-sending "including another
    provider/tool round in the same run, not only the next run".

    B. Conversation creation — implemented in both

    • .NET: FoundryAgent.CreateConversationSessionAsync.
    • Python: FoundryAgent.create_conversation — await client.client.conversations.create(), then
      a session whose service_session_id is the returned id.

    How far the documented workarounds actually go

    Checked in this repository rather than assumed.

    A — the raw-passthrough workaround is real but has a hole the caller cannot close.
    options.additionalProperties is copied onto the wire request verbatim
    (packages/openai/src/chat-client.ts, Object.assign(request, extra)), and an awaited response
    carries the provider object as rawRepresentation, so a caller can read the returned
    agent_session_id after a run and send it on the next one.

    What they cannot do is inject it mid-run. The function-calling loop issues further service calls
    before the caller sees any response, so the tool rounds of the very run that first receives the id
    go out without it. Per .NET's own documentation of the field, omitting it is what causes Foundry to
    create a session — so those rounds can land on a different sandbox than the one just provisioned,
    losing the persistent $HOME the sandbox exists to provide. Not measured against the live
    service
    ; this follows from the reference implementations' code and documentation.

    B — the workaround is complete. FoundryChatClient extends OpenAIChatClient, so a caller can
    call conversations.create() on the underlying client and pass the conv_… id to
    agent.createSession({ serviceSessionId }). Three lines, no framework change.

    Note also that since #104, a session adopts the conversation id its first response reports, so
    plain server-side continuity no longer needs a pre-created conversation at all. What B adds beyond
    the workaround is that the conversation exists — and is visible in the Foundry Project UI — before
    the first turn.

    Recommendation

    • A: approve. Both references implement it, there is no TypeScript-specific reason to diverge,
      and the gap is behavioural rather than ergonomic: no caller-side code can cover the mid-run
      rounds.
    • B: approve, but second and smaller. Both references have it and it is one method, so parity
      is cheap; it is a convenience over an SDK call the caller already has rather than a capability
      they lack.

    Separate PRs either way, per the one-concern rule. A's implementation contract in this issue already
    matches what Python does, including the mid-run re-send and the serialization requirement — note
    that rawRepresentation is not serialized here, so the id has to live in session state to survive a
    round-trip, which is what both references do.

    Recording the decision is the maintainer's call; this comment is the material for it.

  6. shibayan commented on Sep 1, 2026

    @shibayan
    MemberAuthor

    Decision record

    Both tracks were approved by the maintainer on 2026-09-01 and are now implemented and merged:

    • A. Sticky hosted session id — approved, implemented in Carry the Foundry hosted-agent session id with the session that owns it #152 (with Let a chat client ask for a view bound to the run's session #151 adding the
      SessionScopedChatClient capability it rides on). The id is captured from awaited and streamed
      responses, re-sent on every later service request including later tool rounds of the same run,
      kept in session.state so it survives JSON serialization, never shared between sessions, and
      per-call versus session-pinned precedence fails before sending when two non-empty values differ.
    • B. Conversation creation — approved, implemented in Create a Foundry conversation before the first turn #153. One deliberate deviation from the
      letter of this issue's contract: FoundryChatClient.createConversation() returns the conv_...
      id rather than an AgentSession, pairing with agent.createSession({ serviceSessionId }) —
      conversation creation is a transport concern and session construction an agent concern, and one
      function taking both objects would save a single line. Everything else in the contract holds:
      clear ConfigurationError when the SDK has no conversations resource, normal error/cancellation
      boundaries, no implied lifecycle management, and TSDoc/README/CHANGELOG coverage.

    Closing: both tracks have their recorded outcome and their implementation PRs are merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

foundryUsage: [Issues, PRs], Target: Microsoft Foundry integrations

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions