Skip to content

Commit 0af2262

Browse files
committed
inject the date as a dynamic system prompt
1 parent 067cc6b commit 0af2262

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

stac_search/agents/items_search.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime
1+
from datetime import date
22
import logging
33
import os
44
from dataclasses import dataclass
@@ -9,7 +9,6 @@
99
from pydantic_ai import Agent, RunContext
1010
from pystac_client import Client
1111
from pydantic import BaseModel, ConfigDict
12-
from shapely.geometry import shape, mapping
1312

1413
from stac_search.agents.collections_search import (
1514
collection_search,
@@ -47,18 +46,22 @@ class ItemSearchParams:
4746
SMALL_MODEL_NAME,
4847
result_type=ItemSearchParams,
4948
deps_type=Context,
50-
system_prompt=f"""
49+
system_prompt="""
5150
For the given query, extract the start date, end date, and location.
5251
5352
If the query contains a spatial extent, use the `set_spatial_extent` tool to get the location.
5453
If the query contains a temporal range, use the `set_temporal_range` tool to get the datetime.
5554
If the query needs cloud cover filtering, use the `construct_cql2_filter` tool to create a CQL2 filter.
5655
57-
For context, the current date is {datetime.datetime.now().strftime("%Y-%m-%d")}.
5856
""",
5957
)
6058

6159

60+
@search_items_agent.system_prompt
61+
def search_items_agent_system_prompt():
62+
return f"The current date is {date.today()}"
63+
64+
6265
@dataclass
6366
class CollectionQuery:
6467
query: str
@@ -146,11 +149,15 @@ class TemporalRangeResult:
146149
For the given query, if it contains a temporal range, return the start date and end date. If it doesn't contain a temporal range, return None.
147150
The temporal range should be of the form YYYY-MM-DD/YYYY-MM-DD.
148151
For open-ended ranges, use "..", for example "2023-01-01/.." or "../2023-12-31".
149-
The current date is {datetime.datetime.now().strftime("%Y-%m-%d")}.
150152
""",
151153
)
152154

153155

156+
@temporal_range_agent.system_prompt
157+
def temporal_range_agent_system_prompt():
158+
return f"The current date is {date.today()}"
159+
160+
154161
@search_items_agent.tool
155162
async def set_temporal_range(ctx: RunContext[Context]) -> TemporalRangeResult:
156163
result = await temporal_range_agent.run(ctx.deps.query)
@@ -289,11 +296,7 @@ async def item_search(ctx: Context) -> ItemSearchResult:
289296
client = Client.open(STAC_CATALOG_URL)
290297
params = {
291298
"max_items": 20,
292-
# looks like collections is required by Planetary Computer STAC API
293-
# but can be omitted for elasticsearch based STAC APIs like the element84 one
294299
"collections": collections_to_search,
295-
# "collections": ["*"],
296-
# "datetime": "2018",
297300
"datetime": results.data.datetime,
298301
"filter": results.data.filter,
299302
}

0 commit comments

Comments
 (0)