Skip to content

Conversation

mshsheikh
Copy link
Contributor

This update refines the examples/web_search.py snippet to instantiate WebSearchTool.user_location with the proper UserLocation dataclass rather than a raw dict. This change improves type safety, editor autocompletion, and future‑proofs the example against any additional UserLocation fields.

See the official docs for WebSearchTool and its user_location parameter here: https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool

This update refines the `examples/web_search.py` snippet to instantiate `WebSearchTool.user_location` with the proper `UserLocation` dataclass rather than a raw `dict`. This change improves type safety, editor autocompletion, and future‑proofs the example against any additional `UserLocation` fields.

See the official docs for `WebSearchTool` and its `user_location` parameter here:
[https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool](https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool)
This update refines the `examples/web_search.py` snippet to instantiate `WebSearchTool.user_location` with the proper `UserLocation` dataclass rather than a raw `dict`. This change improves type safety, editor autocompletion, and future‑proofs the example against any additional `UserLocation` fields.

See the official docs for `WebSearchTool` and its `user_location` parameter here:
[https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool](https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool)
This update refines the `examples/web_search.py` snippet to instantiate `WebSearchTool.user_location` with the proper `UserLocation` dataclass rather than a raw `dict`. This change improves type safety, editor autocompletion, and future‑proofs the example against any additional `UserLocation` fields.

See the official docs for `WebSearchTool` and its `user_location` parameter here:
[https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool](https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool)
This update refines the `examples/web_search.py` snippet to instantiate `WebSearchTool.user_location` with the proper `UserLocation` dataclass rather than a raw `dict`. This change improves type safety, editor autocompletion, and future‑proofs the example against any additional `UserLocation` fields.

See the official docs for `WebSearchTool` and its `user_location` parameter here:
[https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool](https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.WebSearchTool)
@seratch seratch added the documentation Improvements or additions to documentation label Jul 21, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Thanks for the suggestion. This one could be a good one, but using dict can be handier.

import asyncio

from agents import Agent, Runner, WebSearchTool, trace
from agents.tool import UserLocation # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

the reason mypy says this is that this type comes from openai package, not openai-agents

@seratch seratch closed this Jul 22, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants