Skip to content

Conversation

@TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Jan 23, 2026

Motivation and Context

Part of #761

Description

  1. Add a sample to show how to share a thread between agents in a workflow.
  2. Fix python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py where store=False no longer has effects.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU TaoChenOSU self-assigned this Jan 23, 2026
@TaoChenOSU TaoChenOSU added the workflows Related to Workflows in agent-framework label Jan 23, 2026
Copilot AI review requested due to automatic review settings January 23, 2026 04:15
@TaoChenOSU TaoChenOSU added the samples Issue relates to the samples label Jan 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions github-actions bot changed the title Add sample on how to share a thread between agents in a workflow Python: Add sample on how to share a thread between agents in a workflow Jan 23, 2026
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py94713286%71, 94–95, 149, 154, 173, 175, 179, 183, 185, 187, 189, 206–207, 209–211, 213–214, 216–217, 219–220, 235–237, 239–242, 259, 264, 269, 273, 299, 303, 647–648, 1019, 1081, 1098, 1116, 1121, 1139, 1147–1149, 1166–1167, 1169, 1187–1188, 1190, 1197–1198, 1200, 1235, 1246–1247, 1249, 1268–1269, 1272–1281, 1284–1287, 1289, 1293, 1327, 1360, 1532, 1537, 1541, 1545, 1737, 1747, 1792, 1837–1842, 1864, 1869, 2228, 2237, 2373, 2461–2463, 2502, 2558, 2579, 2588, 2817–2819, 2822–2824, 2828, 2833, 2837, 2949–2951, 2979, 3015, 3033, 3037–3039, 3041, 3052–3053, 3056–3060, 3066
TOTAL17482270484% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3229 213 💤 0 ❌ 0 🔥 1m 2s ⏱️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also please add this new sample to the workflows/README.md.


shared_thread = writer.get_new_thread()
# Set the message store to store messages in memory.
shared_thread.message_store = ChatMessageStore()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better way would be to initialize it via chat_message_store_factory. I noticed that this parameter exists in BaseChatClient.as_agent method, but not in AzureAIProjectAgentProvider. We can add this parameter to provider, pass it to the place where we create ChatAgent, and then in this example, when invoking create_agent, we could also pass chat_message_store_factory=ChatMessageStore.

Copy link
Contributor Author

@TaoChenOSU TaoChenOSU Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern feels a bit weird indeed. A thread is a parallel concept to agent but the chat message store live in the agent.

When I was creating the sample, my first impression was that I could pass in the message store when I call get_new_thread(). Have we considered it?

Also, the fact that we have to also set store to False to have message to actually be stored in the message store is also great.

print(f"User: {query1}")
result1 = await agent.run(query1, thread=thread, store=False)
result1 = await agent.run(
query1, thread=thread, options=OpenAIResponsesOptions(store=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's focus on showing to avoid unnecessary concepts:

Suggested change
query1, thread=thread, options=OpenAIResponsesOptions(store=False)
query1, thread=thread, options={"store": False}


workflow = (
WorkflowBuilder()
.register_agent(lambda: writer, "writer", agent_thread=shared_thread)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some parameter names, because I have no clue what I'm reading here, when I looked up the definition it made a bit more sense, but plain reading this is hard!

"Write a tagline for a budget-friendly eBike.",
# Keyword arguments will be passed to each agent call.
# Setting store=False to avoid storing messages in the service for this example.
options=OpenAIResponsesOptions(store=False),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python samples Issue relates to the samples workflows Related to Workflows in agent-framework

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants