Python: Fix sample bugs: incorrect API params, wrong client types, and invalid options (#4983)

* Fix sample bugs: incorrect API params, wrong client types, and invalid options

- typed_options.py: Fix AnthropicClient model->model_id, wrap raw strings in Message objects for get_response(), fix reasoning_effort->reasoning dict, fix budget_tokens minimum (1024), use OpenAIChatClient not FoundryChatClient, remove unused import

- client_reasoning.py: Fix deprecated model_id to model param

- client_with_hosted_mcp.py: Remove invalid store=True kwarg from Agent.run()

- code_defined_skill.py: Fix precision kwarg to use function_invocation_kwargs

- Various other samples: Fix deprecated API usage and incorrect params

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review comments

- client_with_hosted_mcp.py: Fix remaining store=True kwarg on line 68 to use options dict

- client_with_session.py: Change store=True to store=False to match in-memory persistence demo intent

- typed_options.py: Remove non-existent import and model key from docstring example

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* new sample fixes

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giles Odigwe
2026-03-31 09:58:51 -07:00
committed by GitHub
Unverified
parent 3d09337446
commit 7c2dae8855
13 changed files with 34 additions and 41 deletions
@@ -35,7 +35,7 @@ async def non_streaming_example() -> None:
print("=== Non-streaming Response Example ===")
agent = Agent(
client=AnthropicClient(),
client=AnthropicClient(model_id="claude-sonnet-4-5-20250929"),
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -52,7 +52,7 @@ async def streaming_example() -> None:
print("=== Streaming Response Example ===")
agent = Agent(
client=AnthropicClient(),
client=AnthropicClient(model_id="claude-sonnet-4-5-20250929"),
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -51,9 +51,9 @@ class EchoAgent(BaseAgent):
super().__init__(
name=name,
description=description,
echo_prefix=echo_prefix, # type: ignore
**kwargs,
)
self.echo_prefix = echo_prefix
def run(
self,
@@ -25,7 +25,7 @@ In this case they are here: https://platform.openai.com/docs/api-reference/respo
agent = Agent(
client=OpenAIChatClient[OpenAIChatOptions](model_id="gpt-5"),
client=OpenAIChatClient[OpenAIChatOptions](model="gpt-5"),
name="MathHelper",
instructions="You are a personal math tutor. When asked a math question, "
"reason over how best to approach the problem and share your thought process.",
@@ -50,7 +50,7 @@ async def handle_approvals_with_session(query: str, agent: "SupportsAgentRun", s
"""Here we let the session deal with the previous responses, and we just rerun with the approval."""
from agent_framework import Message
result = await agent.run(query, session=session, store=True)
result = await agent.run(query, session=session, options={"store": True})
while len(result.user_input_requests) > 0:
new_input: list[Any] = []
for user_input_needed in result.user_input_requests:
@@ -65,7 +65,7 @@ async def handle_approvals_with_session(query: str, agent: "SupportsAgentRun", s
contents=[user_input_needed.to_function_approval_response(user_approval.lower() == "y")],
)
)
result = await agent.run(new_input, session=session, store=True)
result = await agent.run(new_input, session=session, options={"store": True})
return result
@@ -75,19 +75,19 @@ async def example_with_session_persistence_in_memory() -> None:
# First conversation
query1 = "What's the weather like in Tokyo?"
print(f"User: {query1}")
result1 = await agent.run(query1, session=session, store=False)
result1 = await agent.run(query1, session=session, options={"store": False})
print(f"Agent: {result1.text}")
# Second conversation using the same session - maintains context
query2 = "How about London?"
print(f"\nUser: {query2}")
result2 = await agent.run(query2, session=session, store=False)
result2 = await agent.run(query2, session=session, options={"store": False})
print(f"Agent: {result2.text}")
# Third conversation - agent should remember both previous cities
query3 = "Which of the cities I asked about has better weather?"
print(f"\nUser: {query3}")
result3 = await agent.run(query3, session=session, store=False)
result3 = await agent.run(query3, session=session, options={"store": False})
print(f"Agent: {result3.text}")
print("Note: The agent remembers context from previous messages in the same session.\n")