Skip to content

fix(Squad.Agents.AI): expose SessionConfig + default OnPermissionRequest#1252

Merged
tamirdresher merged 1 commit into
bradygaster:devfrom
tamirdresher:fix/squad-agents-ai-session-config
Jun 10, 2026
Merged

fix(Squad.Agents.AI): expose SessionConfig + default OnPermissionRequest#1252
tamirdresher merged 1 commit into
bradygaster:devfrom
tamirdresher:fix/squad-agents-ai-session-config

Conversation

@tamirdresher

Copy link
Copy Markdown
Collaborator

What

Squad.Agents.AI 0.1.0-preview.2 has a runtime bug that prevents SquadAgent.CreateSessionAsync() from working: it calls the AsAIAgent(instructions, name) overload which leaves SessionConfig.OnPermissionRequest unset, and the inner Copilot session throws on the first turn:

System.ArgumentException: An OnPermissionRequest handler is required when creating a session.
For example, to allow all permissions, use CreateSessionAsync(new() { OnPermissionRequest = PermissionHandler.ApproveAll });

There is no public escape hatch — ConfigureCopilotClient only exposes CopilotClientOptions, not the per-session SessionConfig that owns the permission handler.

Why

Discovered while building an end-to-end consumer that calls agent.RunAsync(...). The local SDK has the right overload (AsAIAgent(client, sessionConfig, ...)); we just need to use it and expose a ConfigureSession knob.

Fix

  • SquadAgent now uses the AsAIAgent(client, sessionConfig, ownsClient, id, name, description) overload and builds a SessionConfig with:
    • OnPermissionRequest = PermissionHandler.ApproveAll — sensible default for a host-process Squad adapter (the host already chose to instantiate Squad and owns sandboxing decisions).
    • WorkingDirectory defaulting to the resolved Cwd / SquadFolderPath.
    • SystemMessage = new SystemMessageConfig { Content = Instructions } when Instructions is set.
  • New SquadAgentOptions.ConfigureSession: Action<SessionConfig>? — runs after Squad applies its defaults so a consumer can swap in a stricter permission handler, pin the model, restrict tools, etc.
  • New SquadAgentSessionConfigTests (4 cases) covering the new surface.

Verification

Step Result
dotnet build src/Squad.Agents.AI Release ✅ 0 warn, 0 err across net8/9/10
dotnet test test/Squad.Agents.AI.Tests ✅ 47/47 per TFM (141 total)
End-to-end consumer (SquadAgent.CreateSessionAsync() + 3-turn RunAsync against real .squad/ teams) ✅ Works without the SDK fallback this previously required

Breaking changes

None. New optional API only; existing code paths retain their default behavior (just no longer throw at session creation).

Follow-up

This unblocks the working end-to-end consumer example in the CommunityToolkit/Aspire toolkit PR (CommunityToolkit/Aspire#1394).

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Squad.Agents.AI 0.1.0-preview.2 calls `CopilotClient.AsAIAgent(instructions, name)`
which leaves `SessionConfig.OnPermissionRequest` unset. The first call to
`SquadAgent.CreateSessionAsync()` therefore throws:

    System.ArgumentException: An OnPermissionRequest handler is required when
    creating a session. For example, to allow all permissions, use
    CreateSessionAsync(new() { OnPermissionRequest = PermissionHandler.ApproveAll });

There was no public way for consumers to fix it from the outside —
`ConfigureCopilotClient` only exposes `CopilotClientOptions`, not the per-session
`SessionConfig` that owns the permission handler.

What changed
------------
- `SquadAgent` now switches to the `AsAIAgent(client, sessionConfig, ...)` overload
  and constructs a `SessionConfig` with:
    - `OnPermissionRequest = PermissionHandler.ApproveAll` (sensible default for
      a host-process Squad adapter; the host already chose to instantiate Squad
      and is responsible for sandboxing).
    - `WorkingDirectory` defaulting to the resolved `Cwd` / `SquadFolderPath`.
    - `SystemMessage = new SystemMessageConfig { Content = Instructions }` when
      `SquadAgentOptions.Instructions` is set.
- `SquadAgentOptions.ConfigureSession: Action<SessionConfig>?` is new — runs
  after Squad applies its defaults so a consumer can swap in a stricter
  permission handler, pin the model, restrict tools, etc.

Tests
-----
- New `SquadAgentSessionConfigTests` (4 cases) exercising the new surface:
  `ConfigureSession` is settable, runs against the live SessionConfig, can
  replace the permission handler, and can set `AvailableTools`.
- All existing 43 tests still pass per TFM (141 total across net8/9/10).

Verified
--------
- The end-to-end consumer smoke test in
  `C:\Users\tamirdresher\source\repos\squad-agents-ai-consume-test` previously
  had to fall back to the raw SDK because of the missing handler. With this
  change, `SquadAgent.CreateSessionAsync()` returns successfully and
  `RunAsync` drives real 3-turn conversations against `.squad/`-init'd teams.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 10, 2026 04:09
@github-actions

Copy link
Copy Markdown
Contributor

🟡 Impact Analysis — PR #1252

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 3
Files added 1
Files modified 2
Files deleted 0
Modules touched 2

🎯 Risk Factors

  • 3 files changed (≤5 → LOW)
  • 2 modules touched (2-4 → MEDIUM)

📦 Modules Affected

root (2 files)
  • src/Squad.Agents.AI/SquadAgent.cs
  • src/Squad.Agents.AI/SquadAgentOptions.cs
tests (1 file)
  • test/Squad.Agents.AI.Tests/SquadAgentSessionConfigTests.cs

This report is generated automatically for every PR. See #733 for details.

@github-actions

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 4418e85

PR Scope: 🔧 Infrastructure

⚠️ 2 item(s) to address before review

Status Check Details
Single commit 1 commit — clean history
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present No source files changed — changeset not required
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved No Copilot review threads
CI passing 8 check(s) still running

Files Changed (3 files, +133 −1)

File +/−
src/Squad.Agents.AI/SquadAgent.cs +23 −1
src/Squad.Agents.AI/SquadAgentOptions.cs +25 −0
test/Squad.Agents.AI.Tests/SquadAgentSessionConfigTests.cs +85 −0

Total: +133 −1


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

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.

Pull request overview

Fixes a runtime session-creation failure in Squad.Agents.AI by ensuring SquadAgent always builds a SessionConfig with a default permission handler, and exposes an options hook so consumers can further customize per-session settings.

Changes:

  • Construct SessionConfig explicitly (including default OnPermissionRequest) and pass it to CopilotClient.AsAIAgent(...).
  • Add SquadAgentOptions.ConfigureSession to allow consumer customization after Squad defaults are applied.
  • Add tests covering the new ConfigureSession surface.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/Squad.Agents.AI/SquadAgent.cs Builds a SessionConfig (permission handler, working directory, optional system message) and uses the overload that accepts it.
src/Squad.Agents.AI/SquadAgentOptions.cs Adds ConfigureSession: Action<SessionConfig>? with XML docs describing intended usage.
test/Squad.Agents.AI.Tests/SquadAgentSessionConfigTests.cs Adds unit tests for the newly exposed ConfigureSession option.


var inner = client.AsAIAgent(
sessionConfig: sessionConfig,
ownsClient: true,
Comment on lines +117 to +121
/// after Squad has applied its defaults (including an <c>ApproveAll</c>
/// <see cref="SessionConfig.OnPermissionRequest"/> handler and the
/// <see cref="Instructions"/> as the appended system message), so it can override or
/// extend any session-scoped setting such as the permission handler, tool list,
/// model name, or hooks.
Comment on lines +30 to +40
// Simulate what SquadAgent's internal pipeline does so we don't depend on
// a real Copilot CLI process here: the package owns the wiring; this test
// covers the public surface contract.
var simulatedDefault = new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
};
options.ConfigureSession.Invoke(simulatedDefault);

Assert.Equal(1, invocations);
Assert.Same(simulatedDefault, observed);
@tamirdresher tamirdresher merged commit 647f337 into bradygaster:dev Jun 10, 2026
16 checks passed
tamirdresher pushed a commit to tamirdresher/Aspire-1 that referenced this pull request Jun 10, 2026
The original example AppHost only registered a SquadResource. Per the PR
review request from CommunityToolkit#1394, the example now also demonstrates end-to-end
consumption: a downstream ApiApp project receives the squad://...
connection string via .WithReference(squad), parses the team root, and
uses Squad.Agents.AI to drive a real 3-turn conversation against the
referenced team.

What's added
------------
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.ApiApp/
    - ASP.NET minimal API; Program.cs reads ConnectionStrings:research-squad
      (squad://... format), extracts teamRoot, registers SquadAgent via
      AddSquadAgent, exposes POST /ask that runs a 3-turn conversation
      through AgentSession (demonstrates session memory across turns).
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.ServiceDefaults/
    - Standard Aspire ServiceDefaults shape (OTel + service discovery +
      health checks), mirroring the Java example layout.
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.AppHost/
    - Updated to AddProject<...>("squad-api").WithReference(researchSquad)
- Directory.Packages.props
    - Added Squad.Agents.AI 0.1.0-preview.3 (centralized version), the
      preview that ships the SessionConfig/OnPermissionRequest fix needed
      to drive a real conversation. See bradygaster/squad#1252.
- CommunityToolkit.Aspire.slnx
    - 2 new projects added (ApiApp, ServiceDefaults).
- src/CommunityToolkit.Aspire.Hosting.Squad/README.md
    - New "Consume the team from a service project" section pointing
      callers at the new examples/squad/ runnable.

Local verification
------------------
- dotnet build (Release) of all 5 squad-related projects: 0 warn, 0 err
- All 7 unit tests still pass on net10.0 (MTP)
- Squad.Agents.AI 0.1.0-preview.3 restores from nuget.org cleanly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tamirdresher pushed a commit to tamirdresher/Aspire-1 that referenced this pull request Jun 11, 2026
The original example AppHost only registered a SquadResource. Per the PR
review request from CommunityToolkit#1394, the example now also demonstrates end-to-end
consumption: a downstream ApiApp project receives the squad://...
connection string via .WithReference(squad), parses the team root, and
uses Squad.Agents.AI to drive a real 3-turn conversation against the
referenced team.

What's added
------------
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.ApiApp/
    - ASP.NET minimal API; Program.cs reads ConnectionStrings:research-squad
      (squad://... format), extracts teamRoot, registers SquadAgent via
      AddSquadAgent, exposes POST /ask that runs a 3-turn conversation
      through AgentSession (demonstrates session memory across turns).
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.ServiceDefaults/
    - Standard Aspire ServiceDefaults shape (OTel + service discovery +
      health checks), mirroring the Java example layout.
- examples/squad/CommunityToolkit.Aspire.Hosting.Squad.AppHost/
    - Updated to AddProject<...>("squad-api").WithReference(researchSquad)
- Directory.Packages.props
    - Added Squad.Agents.AI 0.1.0-preview.3 (centralized version), the
      preview that ships the SessionConfig/OnPermissionRequest fix needed
      to drive a real conversation. See bradygaster/squad#1252.
- CommunityToolkit.Aspire.slnx
    - 2 new projects added (ApiApp, ServiceDefaults).
- src/CommunityToolkit.Aspire.Hosting.Squad/README.md
    - New "Consume the team from a service project" section pointing
      callers at the new examples/squad/ runnable.

Local verification
------------------
- dotnet build (Release) of all 5 squad-related projects: 0 warn, 0 err
- All 7 unit tests still pass on net10.0 (MTP)
- Squad.Agents.AI 0.1.0-preview.3 restores from nuget.org cleanly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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