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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions examples/tools/web_search.py
Original file line number Diff line number Diff line change
@@ -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



async def main():
agent = Agent(
name="Web searcher",
instructions="You are a helpful agent.",
tools=[WebSearchTool(user_location={"type": "approximate", "city": "New York"})],
tools=[
WebSearchTool(
user_location=UserLocation(
type="approximate",
city="New York"
),
# Feel free to adjust how much context the tool retrieves:
# search_context_size="medium",
)
],
)

with trace("Web search example"):
Expand All @@ -16,8 +26,7 @@ async def main():
"search the web for 'local sports news' and give me 1 interesting update in a sentence.",
)
print(result.final_output)
# The New York Giants are reportedly pursuing quarterback Aaron Rodgers after his ...

# Now this _will_ be localized to New York!

if __name__ == "__main__":
asyncio.run(main())