Skip to content

Python: Fix broken samples and add missing READMEs#5038

Open
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:samples-fix-2
Open

Python: Fix broken samples and add missing READMEs#5038
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:samples-fix-2

Conversation

@giles17
Copy link
Copy Markdown
Contributor

@giles17 giles17 commented Apr 1, 2026

Motivation and Context

Fix runtime errors in several Python samples and add missing README documentation for sample folders.

Description

Sample fixes

  • simple_context_provider.py: instructions was passed as a top-level kwarg to get_response(), but it must be inside the options dict. This caused a silent failure (swallowed by suppress(Exception)) where user info extraction never worked.
  • suspend_resume_session.py: The in-memory session demo used FoundryChatClient() with no args, which requires a credential. Changed to OpenAIChatCompletionClient() to match the docstring intent of comparing service-managed vs in-memory sessions.
  • foundry_chat_client_with_hosted_mcp.py: store=True was passed as a top-level kwarg to Agent.run(), but it must be inside options={"store": True}. This caused a TypeError crash.
  • mem0_basic.py: Preferences query was never sent to the agent before the Mem0 indexing delay, so Mem0 never learned user preferences. Also added missing print for new session result.
  • mem0_sessions.py: Agent-scoped example had no session for multi-turn conversation and combined user_id with agent_id which Mem0 API does not support (memories stored without user_id when agent_id is provided).
  • redis_basics.py: Standalone provider demo printed raw SessionContext object instead of retrieved context messages. Fixed docstring referencing wrong client type.
  • redis_sessions.py: Missing load_dotenv() call caused KeyError on FOUNDRY_PROJECT_ENDPOINT. Fixed docstring referencing wrong client type.
  • azure_redis_conversation.py: Duplicate copyright comment replaced with missing load_dotenv() call.

New READMEs

  • context_providers/README.md: Top-level README covering the two standalone samples and linking to subfolders (azure_ai_search, mem0, redis) that already have their own READMEs.
  • conversations/README.md: README covering suspend/resume sessions, custom history provider, and Redis history provider samples with prerequisites.

Checklist

- simple_context_provider: move instructions kwarg into options dict
- suspend_resume_session: use OpenAIChatCompletionClient for in-memory demo
- foundry_chat_client_with_hosted_mcp: move store kwarg into options dict
- Add README.md for context_providers and conversations sample folders

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 1, 2026 18:35
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Apr 1, 2026
Copy link
Copy Markdown
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.

Pull request overview

Fixes several Python sample runtime issues caused by incorrect keyword argument placement, and adds missing README documentation for sample folders.

Changes:

  • Fix Agent.run() and get_response() option passing by nesting previously top-level kwargs into options={...}.
  • Update the in-memory session example to use OpenAIChatCompletionClient() instead of FoundryChatClient() to match the sample’s intent.
  • Add top-level READMEs for conversations/ and context_providers/ sample folders.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/samples/02-agents/providers/foundry/foundry_chat_client_with_hosted_mcp.py Fixes incorrect store=True kwarg usage by moving it into options for Agent.run().
python/samples/02-agents/conversations/suspend_resume_session.py Switches the in-memory demo client to OpenAIChatCompletionClient() to align with the sample’s described comparison.
python/samples/02-agents/conversations/README.md Adds documentation for conversation/session samples and per-sample prerequisites.
python/samples/02-agents/context_providers/simple_context_provider.py Fixes incorrect instructions= placement by moving it into the options dict for get_response().
python/samples/02-agents/context_providers/README.md Adds documentation for context provider samples and links to subfolder READMEs.

- mem0_basic: send preferences query before sleep so Mem0 can learn them,
  print result from new session recall
- mem0_sessions: add session for multi-turn conversation in agent-scoped
  example, remove user_id from agent-scoped provider (Mem0 API stores
  memories without user_id when agent_id is provided), use single message
  for storing preferences
- redis_basics: print retrieved context messages instead of raw object
- redis_sessions: add missing load_dotenv() call
- redis_basics/redis_sessions: fix docstrings referencing wrong client type
- azure_redis_conversation: replace duplicate copyright with load_dotenv()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giles17 giles17 enabled auto-merge April 1, 2026 20:36
giles17 and others added 2 commits April 1, 2026 13:44
openai_responses_agent.py was renamed to openai_agent.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants