Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

resume_session raised TypeError: Object of type Tool is not JSON serializable when called with a config dict containing session_id and tools. This occurred because the method only accepted the two-argument form resume_session(session_id, config), unlike create_session which accepts a single config dict.

Changes

API enhancement:

  • Added overload to support both calling styles:
    # Two-argument style (existing)
    session = await client.resume_session("session-123", {"tools": [my_tool]})
    
    # Single-argument style (new)
    session = await client.resume_session({
        "session_id": "session-123",
        "tools": [my_tool]
    })

Type system:

  • Added session_id field to ResumeSessionConfig TypedDict
  • Added type overloads for both calling patterns

Validation:

  • Early argument validation with clear error messages for missing session_id, mixed argument styles, and invalid types
  • Validation occurs before client connection check for better error UX

Tests:

  • E2E tests for both calling styles

Backward compatible - existing two-argument API unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Resuming sessions with tools raises a TypeError exception.</issue_title>
<issue_description>Trying to make sure the same tools can still be used when resuming sessions, but trying to do so causes an error:

TypeError: Object of type Tool is not JSON serializable

Image

However, passing tools just works fine when using create_session method... same tools, the only thing that changed is the mode of operations (create session or resume session method)

Here is the sample code trying to do so, assuming that first run was successful after using create_session method with tools provided before, then resuming it with same or different set of tools:

import asyncio
import copilot
from pydantic import BaseModel, Field

class ToolGetWeatherParams(BaseModel):
    location: str = Field(..., description="The location to get the weather for.")

@copilot.define_tool(description="Get Weather today")
def tool_get_weather(params: ToolGetWeatherParams) -> str:
    return f"The weather in {params.location} is sunny with a high of 75°F."

async def main():
    client = copilot.CopilotClient()
    await client.start()

    # Note that this works if I use create_session
    session = await client.resume_session({
        "session_id": "test-session-123",
        "tools": [tool_get_weather]
    })
    response = await session.send_and_wait({"prompt": "What is the weather in London?"})
    print(response.data.content)

    await session.destroy()
    
    # Stop
    await client.stop()

asyncio.run(main())

Expected behavior that it should resume session with no errors and can call tools.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
@overload
async def resume_session(
self, session_id: str, config: Optional[ResumeSessionConfig] = None
) -> CopilotSession: ...
Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
) -> CopilotSession: ...

@overload
async def resume_session(self, config: ResumeSessionConfig) -> CopilotSession: ...
Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TypeError when resuming sessions with tools Support dict config in resume_session to match create_session API Jan 26, 2026
Copilot AI requested a review from friggeri January 26, 2026 17:41
@friggeri friggeri closed this Jan 26, 2026
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.

Resuming sessions with tools raises a TypeError exception.

2 participants