You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
I was doing a small personal project where the objective is to given a prompt with a country,get an agent to display a map of the country.
I am using langchain and langgraph to create the agent, earth engine to get the data and geemap to display the map.
Going to simplify a bit the code for the sake of the example. The function I was using was something like this:
importeeimportgeemapfromlangchain_cohereimportChatCoherefromlangchain.toolsimporttoolfromIPython.displayimportdisplayfromlanggraph.prebuiltimportcreate_react_agentimportasyncioee.Authenticate()
ee.Initialize(project="unicef-geospatial")
defget_uruguay_map():
"""Displays a map of Uruguay"""country_boundries=ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
uruguay_boundries=country_boundries.filter(ee.Filter.eq("country_na", "Uruguay"))
country_map=geemap.Map()
country_map.center_object(uruguay_boundries)
country_map.add_layer(uruguay_boundries, {}, "Uruguay Boundaries")
display(country_map)
return"success"IfIcallthefunctiondirectly, itworksasexpected.
When changing the function to a tool and hooking it up to the agent, it doesn't work as expected. The code was having at the start was:
@tooldefget_uruguay_map():
"""Displays a map of Uruguay"""country_boundries=ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
uruguay_boundries=country_boundries.filter(ee.Filter.eq("country_na", "Uruguay"))
country_map=geemap.Map()
country_map.center_object(uruguay_boundries)
country_map.add_layer(uruguay_boundries, {}, "Uruguay Boundaries")
display(country_map)
return"success"llm=ChatCohere(temperature=0.0)
tools= [get_uruguay_map]
graph=create_react_agent(
tools=tools,
model=llm,
)
# %%inputs= {
"messages": [
{
"role": "user",
"content": "Show me the map of Uruguay",
}
]
}
graph.invoke(inputs)
With that code, I was getting the following output:
ToolMessage(content='Error: RuntimeError("There is no current event loop in thread \'ThreadPoolExecutor-3_0\'.")\n Please fix your mistakes.', name='get_uruguay_map', id='4bba79a1-c59a-4fbb-b065-f7e51122db5c', tool_call_id='eec8f8104e7a44a4ba63044c6a06dfa5', status='error'),
Which I couldn't diagnose but I found that it could be fixed by setting the event loop.
@tooldefget_uruguay_map():
"""Displays a map of Uruguay"""loop=asyncio.new_event_loop()
asyncio.set_event_loop(loop)
country_boundries=ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
uruguay_boundries=country_boundries.filter(ee.Filter.eq("country_na", "Uruguay"))
country_map=geemap.Map()
country_map.center_object(uruguay_boundries)
country_map.add_layer(uruguay_boundries, {}, "Uruguay Boundaries")
display(country_map)
return"success"llm=ChatCohere(temperature=0.0)
tools= [get_uruguay_map]
graph=create_react_agent(
tools=tools,
model=llm,
)
# %%inputs= {
"messages": [
{
"role": "user",
"content": "Show me the map of Uruguay",
}
]
}
graph.invoke(inputs)
However, now instead of getting the map centered on Uruguay, I am getting the map centered on the world, even though the layer is properly displayed.
I am not sure why this is happening or how to properly diagnose/fix the issue.
Any thoughts?
System Info
System Information
------------------
> OS: Darwin
> OS Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:00:32 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6030
> Python Version: 3.12.7 (main, Oct 1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)]
Package Information
-------------------
> langchain_core: 0.3.21
> langchain: 0.3.9
> langchain_community: 0.3.9
> langsmith: 0.1.147
> langchain_cohere: 0.3.3
> langchain_experimental: 0.3.3
> langchain_openai: 0.2.11
> langchain_text_splitters: 0.3.2
> langgraph_sdk: 0.1.43
Optional packages not installed
-------------------------------
> langserve
Other Dependencies
------------------
> aiohttp: 3.11.10
> async-timeout: Installed. No version info available.
> cohere: 5.13.3
> dataclasses-json: 0.6.7
> httpx: 0.28.1
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.4
> openai: 1.57.0
> orjson: 3.10.12
> packaging: 24.2
> pandas: 2.2.3
> pydantic: 2.10.3
> pydantic-settings: 2.6.1
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.36
> tabulate: 0.9.0
> tenacity: 9.0.0
> tiktoken: 0.8.0
> typing-extensions: 4.12.2
The text was updated successfully, but these errors were encountered:
It looks like you're running in a Jupyter environment, which already has an event loop running. I suspect this might be causing the issue.
If you're in Jupyter, can the same code run in a .py file?
Or try using nest_asyncio to see if it solves the problem.
Checked other resources
I was doing a small personal project where the objective is to given a prompt with a country,get an agent to display a map of the country.
I am using langchain and langgraph to create the agent, earth engine to get the data and geemap to display the map.
Going to simplify a bit the code for the sake of the example. The function I was using was something like this:
When changing the function to a tool and hooking it up to the agent, it doesn't work as expected. The code was having at the start was:
With that code, I was getting the following output:
Which I couldn't diagnose but I found that it could be fixed by setting the event loop.
However, now instead of getting the map centered on Uruguay, I am getting the map centered on the world, even though the layer is properly displayed.
I am not sure why this is happening or how to properly diagnose/fix the issue.
Any thoughts?
System Info
The text was updated successfully, but these errors were encountered: