Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3785,8 +3785,8 @@ def __init__(

@property
def text(self) -> str:
"""Get the concatenated text of all messages."""
return "".join(msg.text for msg in self.messages) if self.messages else ""
"""Get the concatenated text of all messages, with a newline between non-empty message texts."""
return "\n".join(text for msg in self.messages if (text := msg.text))

@property
def value(self) -> ResponseModelT | None:
Expand Down
16 changes: 14 additions & 2 deletions python/packages/core/tests/core/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def test_agent_response_value_parses_final_message_with_response_format() -> Non
response_format=OutputModel,
)

assert response.text == '{"skill_name": "building-permit-compliance"}{"response": "Hello"}'
assert response.text == '{"skill_name": "building-permit-compliance"}\n{"response": "Hello"}'
assert response.value is not None
assert response.value.response == "Hello"

Expand Down Expand Up @@ -2254,7 +2254,19 @@ def test_agent_run_response_init_none_messages() -> None:

def test_agent_run_response_text_property(chat_message: Message) -> None:
response = AgentResponse(messages=[chat_message, chat_message])
assert response.text == "HelloHello"
assert response.text == "Hello\nHello"


def test_agent_run_response_text_separates_messages_around_tool_calls() -> None:
# A preamble before a tool call and the final answer are separate messages and must not run together
response = AgentResponse(
messages=[
Message("assistant", [Content.from_text("Let me check."), Content.from_function_call("c1", "get_weather")]),
Message("tool", [Content.from_function_result("c1", result="sunny")]),
Message("assistant", ["It is sunny."]),
]
)
assert response.text == "Let me check.\nIt is sunny."


def test_agent_run_response_text_property_empty() -> None:
Expand Down
Loading