Skip to content

Resuming sessions with tools raises a TypeError exception. #167

@zavocc

Description

@zavocc

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions