Skip to content

[Custom Agents] Preselecting agent does not work #1018

@vatsa-msft

Description

@vatsa-msft

Bug

When agent is provided in createSession config to pre-select a custom agent, the agent is not active from start.

Versions

  • SDK: @github/copilot-sdk 0.2.0 / 0.2.1
  • Runtime: @github/copilot 1.0.17

Expected Behavior

Per the docs:

You can pass agent in the session config to pre-select which custom agent should be active when the session starts. This is equivalent to calling session.rpc.agent.select() after creation.

https://github.com/github/copilot-sdk/blob/main/docs/features/custom-agents.md#selecting-an-agent-at-session-creation

Both approaches should produce the same result — the selected agent's prompt is used as the active system prompt from the first message.

Actual Behavior

  • agent= in session config: The LLM receives the systemMessage content (or the SDK default prompt). The agent's prompt is not injected. Confirmed by inspecting the system field in the LLM API request.
  • rpc.agent.select() after creation: The LLM receives the agent's prompt as expected. Confirmed by a marker string in the agent's prompt appearing in the LLM's first response.

Reproduction

session = await client.create_session(
    on_permission_request=PermissionHandler.approve_all,
    system_message={"mode": "replace", "content": "You are a helpful assistant."},
    custom_agents=[
        {
            "name": "researcher",
            "prompt": "You are a researcher. Begin every response with RESEARCHER_ACTIVE.",
        },
    ],
    agent="researcher",  # Pre-select
)

response = await session.send_and_wait("Hello")
# Expected: response starts with "RESEARCHER_ACTIVE"
# Actual: response does NOT contain "RESEARCHER_ACTIVE" — agent prompt not injected

Workaround

Call rpc.agent.select() after session creation:

  session = await client.create_session(...)
  await session.rpc.agent.select(SessionAgentSelectParams(name="researcher"))
  response = await session.send_and_wait("Hello")
  # Works: response starts with "RESEARCHER_ACTIVE"

Notes

  • This may be related to how systemMessage: { mode: "replace" } interacts with agent selection. It's possible replace mode overwrites the agent's prompt. However, the docs do not mention this interaction, and rpc.agent.select() correctly overrides the system message regardless of mode.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions