Skip to content

Deserialization Error When Loading a Serialized Agent That Includes a Tool #9587

Open
@samirsalman

Description

@samirsalman

Describe the bug
Attempting to load a serialized pipeline that includes an Agent with at least one tool results in a deserialization error. This prevents the use of such agents after serialization, effectively breaking the .run() functionality for pipelines that include tools.

Error message

raise DeserializationError(f"The final attribute is not callable: {attr_value}")
haystack.core.errors.DeserializationError: The final attribute is not callable: Tool(name='get_weather', description='Get the weather for a given location.', parameters={'properties': {'location': {'type': 'string', 'description': 'The location to get the weather for.'}}, 'required': ['location'], 'type': 'object'}, function=<function get_weather at 0x7f23923abd90>, outputs_to_string=None, inputs_from_state=None, outputs_to_state=None)

Expected behavior
The pipeline should be deserialized without errors, and the agent should be fully functional and callable via the .run() method, including the ability to use the tool.

To Reproduce
Run the following Python code to reproduce the issue:

from typing import Annotated

from haystack import Pipeline
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import tool


@tool
def get_weather(location: Annotated[str, "The location to get the weather for."]) -> str:
    "Get the weather for a given location."
    return f"The weather in {location} is sunny with a high of 30°C."


pipeline = Pipeline()

weather_agent = Agent(
    chat_generator=OpenAIChatGenerator(),
    tools=[get_weather],
    system_prompt="""
You are a helpful assistant that can provide weather information.
You can use the get_weather tool to get the weather for a specific location.
""",
)

pipeline.add_component(
    "weather_agent",
    weather_agent,
)

with open("test_serialization.yaml", "w") as f:
    f.write(pipeline.dumps())

pipeline = Pipeline.loads(open("test_serialization.yaml").read())

pipeline.run(
    {
        "weather_agent": {
            "messages": [
                ChatMessage.from_user("What is the weather like in New York?"),
            ]
        }
    }
)

System:

  • Haystack version (commit or version number): 2.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High priority, add to the next sprint

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions