Skip to content

ToolCall should be serializable #412

Open
@fightingmonk

Description

@fightingmonk

You can use Pydantic's BaseModel.model_dump_json() to serialize a Message for persistence. However, if the message has a ToolCall then model_dump_json throws an exception because ToolCall.InvocableTool is a Callable that Pydantic can't serialize.

Conversation history serialization is important for resilient workflows and agents. I want to snapshot the current message history and requested tool calls before I start invoking the tools, so I can resume the process if something goes wring while a tool is running. I'm starting to think this is a blocker to building out a resilient agent with ell. Also a huge help during development so you can make code changes and resume the workflow or agent from any state snapshot.

Do you have ideas on how you'd approach solving this? I'm happy to put together a PR.

Here's a reproduction of the issue:

import ell

@ell.complex(model="gpt-4o")
def test_no_tool():
    return "say hello"

message = test_no_tool()
print("Normal message serializes")
print(message.model_dump_json())

@ell.tool()
def be_a_tool():
    """This is the be_a_tool function"""
    return "hi"

@ell.complex(model="gpt-4o", tools=[be_a_tool])
def test_tool():
    return "call the be_a_tool tool"

message = test_tool()
if message.tool_calls:
    print("Message with a ToolCall throws an exception...")
    print(message.model_dump_json())
else:
    print("Test setup failed, LLM didn't request a tool call")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions