Skip to content

Commit d07f435

Browse files
authored
Merge branch 'main' into yann/wor-3802-have-list_models-pass-the-instructions-and-requires_tools-to
2 parents 606f66b + 5bb4446 commit d07f435

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ Tools allow enhancing an agent's capabilities by allowing it to call external fu
543543

544544
WorkflowAI hosts a few tools:
545545

546-
- `@browser-text` allows fetching the content of a web page
547-
- `@search` allows performing a web search
546+
- `@browser-text` allows fetching the text content of a web page
547+
- `@search-google` allows performing a web search
548548

549549
Hosted tools tend to be faster because there is no back and forth between the client and the WorkflowAI API. Instead,
550550
if a tool call is needed, the WorkflowAI API will call it within a single request.
@@ -557,7 +557,7 @@ To use a tool, simply add it's handles to the instructions (the function docstri
557557
@workflowai.agent()
558558
async def analyze_call_feedback(input: CallFeedbackInput) -> CallFeedbackOutput:
559559
"""
560-
You can use @search and @browser-text to retrieve information about the name.
560+
You can use @search-google and @browser-text to retrieve information about the name.
561561
"""
562562
...
563563
```

examples/02_agent_with_tools.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""
2+
This example demonstrates how to create a WorkflowAI agent that uses tools to enhance its capabilities.
3+
It showcases:
4+
5+
1. Using built-in WorkflowAI tools (@search-google)
6+
2. Creating and using custom tools
7+
3. Combining multiple tools in a single agent
8+
"""
9+
10+
import asyncio
11+
from datetime import date, datetime
12+
from zoneinfo import ZoneInfo
13+
14+
from pydantic import BaseModel, Field
15+
16+
import workflowai
17+
from workflowai import Model
18+
19+
20+
def get_current_date() -> str:
21+
"""Return today's date in ISO format (YYYY-MM-DD)"""
22+
return datetime.now(tz=ZoneInfo("UTC")).date().isoformat()
23+
24+
25+
def calculate_days_between(date1: str, date2: str) -> int:
26+
"""Calculate the number of days between two dates in ISO format (YYYY-MM-DD)"""
27+
d1 = date.fromisoformat(date1)
28+
d2 = date.fromisoformat(date2)
29+
return abs((d2 - d1).days)
30+
31+
32+
class HistoricalEventInput(BaseModel):
33+
"""Input model for querying historical events."""
34+
query: str = Field(
35+
description="A query about a historical event",
36+
examples=[
37+
"When was the first moon landing?",
38+
"When did World War II end?",
39+
"When was the Declaration of Independence signed?",
40+
],
41+
)
42+
43+
44+
class HistoricalEventOutput(BaseModel):
45+
"""Output model containing information about a historical event."""
46+
event_date: str = Field(
47+
description="The date of the event in ISO format (YYYY-MM-DD)",
48+
examples=["1969-07-20", "1945-09-02", "1776-07-04"],
49+
)
50+
event_description: str = Field(
51+
description="A brief description of the event",
52+
examples=[
53+
"Apollo 11 astronauts Neil Armstrong and Buzz Aldrin became the first humans to land on the Moon",
54+
"Japan formally surrendered to the Allied Powers aboard the USS Missouri in Tokyo Bay",
55+
],
56+
)
57+
days_since_event: int = Field(
58+
description="Number of days between the event and today",
59+
examples=[19876, 28490, 90123],
60+
)
61+
62+
63+
@workflowai.agent(
64+
id="historical-event-analyzer",
65+
model=Model.GEMINI_1_5_FLASH_LATEST,
66+
tools=[get_current_date, calculate_days_between],
67+
)
68+
async def analyze_historical_event(event_input: HistoricalEventInput) -> HistoricalEventOutput:
69+
"""
70+
Find information about historical events and calculate days since they occurred.
71+
72+
You have access to these tools:
73+
1. @search-google - Use this to find accurate information about events
74+
2. get_current_date - Use this to get today's date for calculating days since the event
75+
3. calculate_days_between - Calculate days between two dates (format: YYYY-MM-DD)
76+
77+
Guidelines:
78+
1. Use @search-google to find accurate event information
79+
2. Use get_current_date to get today's date
80+
3. Use calculate_days_between to compute days since the event
81+
4. Return dates in ISO format (YYYY-MM-DD)
82+
5. Be precise with dates and descriptions
83+
"""
84+
...
85+
86+
87+
async def main():
88+
# Example: Query about the moon landing
89+
print("\nExample: First Moon Landing")
90+
print("-" * 50)
91+
run = await analyze_historical_event.run(
92+
HistoricalEventInput(query="When was the first moon landing?"),
93+
)
94+
print(run)
95+
96+
# Example: Query about World War II
97+
print("\nExample: End of World War II")
98+
print("-" * 50)
99+
run = await analyze_historical_event.run(
100+
HistoricalEventInput(query="When did World War II end?"),
101+
)
102+
print(run)
103+
104+
105+
if __name__ == "__main__":
106+
asyncio.run(main())

workflowai/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def _default_app_url():
1717
return "https://workflowai.com"
1818

1919

20-
WORKFLOWAI_APP_URL = os.getenv("WORKFLOWAI_APP_URL", _default_app_url)
20+
WORKFLOWAI_APP_URL = os.getenv("WORKFLOWAI_APP_URL", _default_app_url())
2121

2222
WORKFLOWAI_API_KEY = os.getenv("WORKFLOWAI_API_KEY", "")

0 commit comments

Comments
 (0)