Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions python/packages/core/agent_framework/_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ async def run(
)
return AgentRunResponse(
messages=response.messages,
conversation_id=response.conversation_id,
response_id=response.response_id,
created_at=response.created_at,
usage_details=response.usage_details,
Expand Down Expand Up @@ -1045,6 +1046,7 @@ async def run_stream(
role=update.role,
author_name=update.author_name,
response_id=update.response_id,
conversation_id=update.conversation_id,
message_id=update.message_id,
created_at=update.created_at,
additional_properties=update.additional_properties,
Expand Down
6 changes: 6 additions & 0 deletions python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,7 @@ def __init__(
| MutableMapping[str, Any]
| list[MutableMapping[str, Any]]
| None = None,
conversation_id: str | None = None,
response_id: str | None = None,
created_at: CreatedAtT | None = None,
usage_details: UsageDetails | MutableMapping[str, Any] | None = None,
Expand All @@ -2807,6 +2808,7 @@ def __init__(

Keyword Args:
messages: The list of chat messages in the response.
conversation_id: The ID of the current conversation.
response_id: The ID of the chat response.
created_at: A timestamp for the chat response.
usage_details: The usage details for the chat response.
Expand Down Expand Up @@ -2835,6 +2837,7 @@ def __init__(
usage_details = UsageDetails.from_dict(usage_details)

self.messages = processed_messages
self.conversation_id = conversation_id
self.response_id = response_id
self.created_at = created_at
self.usage_details = usage_details
Expand Down Expand Up @@ -2961,6 +2964,7 @@ def __init__(
text: TextContent | str | None = None,
role: Role | MutableMapping[str, Any] | str | None = None,
author_name: str | None = None,
conversation_id: str | None = None,
response_id: str | None = None,
message_id: str | None = None,
created_at: CreatedAtT | None = None,
Expand All @@ -2975,6 +2979,7 @@ def __init__(
text: Optional text content of the update.
role: The role of the author of the response update (Role, string, or dict
author_name: Optional name of the author of the response update.
conversation_id: Optional identifier for the conversation of which this update is a part.
response_id: Optional ID of the response of which this update is a part.
message_id: Optional ID of the message of which this update is a part.
created_at: Optional timestamp for the chat response update.
Expand All @@ -2999,6 +3004,7 @@ def __init__(
self.contents = parsed_contents
self.role = role
self.author_name = author_name
self.conversation_id = conversation_id
self.response_id = response_id
self.message_id = message_id
self.created_at = created_at
Expand Down
30 changes: 30 additions & 0 deletions python/packages/core/tests/core/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ChatMessage,
ChatMessageStore,
ChatResponse,
ChatResponseUpdate,
Context,
ContextProvider,
FunctionCallContent,
Expand Down Expand Up @@ -343,6 +344,35 @@ async def test_chat_agent_run_stream_context_providers(chat_client: ChatClientPr
assert mock_provider.invoked_called


async def test_chat_agent_run_stream_context_providers_with_conversation_id(chat_client: ChatClientProtocol) -> None:
"""Test that context providers work with run_stream method."""
mock_provider = MockContextProvider(messages=[ChatMessage(role=Role.SYSTEM, text="Stream context instructions")])
mock_response_updates = [
ChatResponseUpdate(
messages=[ChatMessage(role=Role.ASSISTANT, contents=[TextContent("test response")])],
conversation_id="conv-123",
),
ChatResponseUpdate(
messages=[ChatMessage(role=Role.ASSISTANT, contents=[TextContent(" another update")])],
conversation_id="conv-123",
),
ChatResponseUpdate(
messages=[ChatMessage(role=Role.ASSISTANT, contents=[TextContent(" final update")])],
conversation_id="conv-123",
),
]
chat_client.streaming_responses = [mock_response_updates]
agent = ChatAgent(chat_client=chat_client, context_providers=mock_provider)

# Collect all stream updates
updates: list[AgentRunResponseUpdate] = []
thread = agent.get_new_thread()
async for update in agent.run_stream("Hello", thread=thread):
updates.append(update)

assert thread.service_thread_id == "conv-123"


async def test_chat_agent_multiple_context_providers(chat_client: ChatClientProtocol) -> None:
"""Test that multiple context providers work together."""
provider1 = MockContextProvider(messages=[ChatMessage(role=Role.SYSTEM, text="First provider instructions")])
Expand Down
2 changes: 2 additions & 0 deletions python/packages/core/tests/core/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ def test_agent_run_response_update_all_content_types():
"contents": [{"type": "text", "text": "Answer"}],
},
],
"conversation_id": "conv-123",
"response_id": "run-123",
"usage_details": {
"type": "usage_details",
Expand All @@ -1833,6 +1834,7 @@ def test_agent_run_response_update_all_content_types():
],
"role": {"type": "role", "value": "assistant"},
"message_id": "msg-123",
"conversation_id": "conv-123",
"response_id": "run-123",
"author_name": "Agent",
},
Expand Down
Loading