Skip to content

docs(examples): use UserLocation dataclass in WebSearchTool example #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

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.

@@ -1,13 +1,23 @@
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