Skip to content

[Bug] System prompt lacks space when both structured output and tools are involved #4073

@undera

Description

@undera

Description

If Agent is configured with structured output and tools, the additions to system prompt lack space between them.
This is quite clear from source code, lines:

When both of conditions work together, the resulting prompt contains: Do not reflect on the quality of the returned search results in your responseProvide your output as a JSON containing the following fields

IMO any addition to system prompt should be done with assumption that there might be no whitespace at the end of the preceding system prompt.

Steps to Reproduce

Run the provided hermetic test case

Agent Configuration (if applicable)

from agno.agent import Agent
from agno.models.anthropic import Claude
from anthropic.types import Message, Usage, TextBlock
from pydantic import BaseModel


class FakeClaude(Claude):
    def invoke(self, *args, **kwargs):
        return Message(
            content=[TextBlock(text='{"response": "worked"}', type="text")],
            id="test1",
            model=self.id,
            role="assistant",
            type="message",
            usage=Usage(input_tokens=1, output_tokens=2),
        )


class Output(BaseModel):
    response: str


def tool():
    return "hello"


agent = Agent(model=FakeClaude(), response_model=Output, tools=[tool])

result = agent.run()
print(result.messages[0].content)
assert "responseProvide" not in result.messages[0].content, result.messages[0].content

Expected Behavior

The best is to have "\n\n" before each addition to system prompt, to ensure whitespace and markdown flow.

Actual Behavior

It uses system prompt with "responseProvide" glued together.

Screenshots or Logs (if applicable)

No response

Environment

- OS: Linux
- Agno: 1.7.6 (and master)

Possible Solutions (optional)

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions