langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
36.62k stars 4.3k forks source link

Errors showing when running "Tool Calling Agent" component #4463

Closed SavvySupport closed 1 week ago

SavvySupport commented 3 weeks ago

Bug Description

In terminal, I can see errors come up when trying to run the "Tool Calling Agent". Same occurs when trying to run the "OpenAI Tools Agent".

Reproduction

  1. When running the "Tool Calling" Agent flow I have here https://prnt.sc/_dn5tkLiHKid, I can see these errors in my Terminal.
  2. It manages to process the request and provide an output in Langflow UI.

[11/08/24 03:55:56] ERROR 2024-11-08 03:55:56 - ERROR - service - Error ending trace Search API (SearchAPI-1sPfu) service.py:185 Traceback (most recent call last):

                           File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap                                                              
                             self._bootstrap_inner()                                                                                                     
                             |    -> <function Thread._bootstrap_inner at 0x7f60057dfe20>                                                                
                             -> <Thread(asyncio_1, started 140048073750080)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner                                                       
                             self.run()                                                                                                                  
                             |    -> <function Thread.run at 0x7f60057dfb50>                                                                             
                             -> <Thread(asyncio_1, started 140048073750080)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 953, in run                                                                     
                             self._target(*self._args, **self._kwargs)                                                                                   
                             |    |        |    |        |    -> {}                                                                                      
                             |    |        |    |        -> <Thread(asyncio_1, started 140048073750080)>                                                 
                             |    |        |    -> (<weakref at 0x7f5f79d74d10; to 'ThreadPoolExecutor' at 0x7f5f92699900>,                              
                         <_queue.SimpleQueue object at 0x7f5f7aa02700>, None,...                                                                         
                             |    |        -> <Thread(asyncio_1, started 140048073750080)>                                                               
                             |    -> <function _worker at 0x7f6002555750>                                                                                
                             -> <Thread(asyncio_1, started 140048073750080)>                                                                             
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83, in _worker                                                  
                             work_item.run()                                                                                                             
                             |         -> <function _WorkItem.run at 0x7f6002555870>                                                                     
                             -> <concurrent.futures.thread._WorkItem object at 0x7f5f79ea5a20>                                                           
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                                      
                             result = self.fn(*self.args, **self.kwargs)                                                                                 
                                      |    |   |    |       |    -> {}                                                                                   
                                      |    |   |    |       -> <concurrent.futures.thread._WorkItem object at 0x7f5f79ea5a20>                            
                                      |    |   |    -> ()                                                                                                
                                      |    |   -> <concurrent.futures.thread._WorkItem object at 0x7f5f79ea5a20>                                         
                                      |    -> functools.partial(<built-in method run of _contextvars.Context object at 0x7f5f90ac46c0>,                  
                         <bound method TracingService._end_t...                                                                                          
                                      -> <concurrent.futures.thread._WorkItem object at 0x7f5f79ea5a20>                                                  
                         > File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py", line 177, in                 
                         _end_traces                                                                                                                     
                             tracer.end_trace(                                                                                                           
                             |      -> <function LangSmithTracer.end_trace at 0x7f5ffc95c160>                                                            
                             -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                           
                           File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py", line 128, in               
                         end_trace                                                                                                                       
                             child = self._children                                                                                                      
                                     |    |         -> 'Search API (SearchAPI-1sPfu)'                                                                    
                                     |    -> {'Text Input (TextInput-08dAi)': RunTree(id=UUID('7e39ff8f-0ab4-4702-b27e-4665669f6c41'),                   
                         name='Text Input (TextInput-08dAi)'...                                                                                          
                                     -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                   

                         KeyError: 'Search API (SearchAPI-1sPfu)'                                                                                        

                         ╭────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────╮               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py:177 in _end_traces   │               
                         │                                                                                                               │               
                         │   174 │   │   for tracer in self._tracers.values():                                                           │               
                         │   175 │   │   │   if tracer.ready:                                                                            │               
                         │   176 │   │   │   │   try:                                                                                    │               
                         │ ❱ 177 │   │   │   │   │   tracer.end_trace(                                                                   │               
                         │   178 │   │   │   │   │   │   trace_id=trace_id,                                                              │               
                         │   179 │   │   │   │   │   │   trace_name=trace_name,                                                          │               
                         │   180 │   │   │   │   │   │   outputs=self.outputs[trace_name],                                               │               
                         │                                                                                                               │               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py:128 in end_trace   │               
                         │                                                                                                               │               
                         │   125 │   ):                                                                                                  │               
                         │   126 │   │   if not self._ready:                                                                             │               
                         │   127 │   │   │   return                                                                                      │               
                         │ ❱ 128 │   │   child = self._children[trace_name]                                                              │               
                         │   129 │   │   raw_outputs = {}                                                                                │               
                         │   130 │   │   processed_outputs = {}                                                                          │               
                         │   131 │   │   if outputs:                                                                                     │               
                         ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯               
                         KeyError: 'Search API (SearchAPI-1sPfu)'                                                                                        
                ERROR    2024-11-08 03:55:56 - ERROR    - service - Error ending trace OpenAI (OpenAIModel-56zaX)                          service.py:185
                         Traceback (most recent call last):                                                                                              

                           File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap                                                              
                             self._bootstrap_inner()                                                                                                     
                             |    -> <function Thread._bootstrap_inner at 0x7f60057dfe20>                                                                
                             -> <Thread(asyncio_0, started 140049077233216)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner                                                       
                             self.run()                                                                                                                  
                             |    -> <function Thread.run at 0x7f60057dfb50>                                                                             
                             -> <Thread(asyncio_0, started 140049077233216)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 953, in run                                                                     
                             self._target(*self._args, **self._kwargs)                                                                                   
                             |    |        |    |        |    -> {}                                                                                      
                             |    |        |    |        -> <Thread(asyncio_0, started 140049077233216)>                                                 
                             |    |        |    -> (<weakref at 0x7f5fbc21d030; to 'ThreadPoolExecutor' at 0x7f5fbcb136d0>,                              
                         <_queue.SimpleQueue object at 0x7f5fbc21bbf0>, None,...                                                                         
                             |    |        -> <Thread(asyncio_0, started 140049077233216)>                                                               
                             |    -> <function _worker at 0x7f6002555750>                                                                                
                             -> <Thread(asyncio_0, started 140049077233216)>                                                                             
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83, in _worker                                                  
                             work_item.run()                                                                                                             
                             |         -> <function _WorkItem.run at 0x7f6002555870>                                                                     
                             -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedf60>                                                           
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                                      
                             result = self.fn(*self.args, **self.kwargs)                                                                                 
                                      |    |   |    |       |    -> {}                                                                                   
                                      |    |   |    |       -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedf60>                            
                                      |    |   |    -> ()                                                                                                
                                      |    |   -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedf60>                                         
                                      |    -> functools.partial(<built-in method run of _contextvars.Context object at 0x7f5fb4285580>,                  
                         <bound method TracingService._end_t...                                                                                          
                                      -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedf60>                                                  
                         > File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py", line 177, in                 
                         _end_traces                                                                                                                     
                             tracer.end_trace(                                                                                                           
                             |      -> <function LangSmithTracer.end_trace at 0x7f5ffc95c160>                                                            
                             -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                           
                           File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py", line 128, in               
                         end_trace                                                                                                                       
                             child = self._children                                                                                                      
                                     |    |         -> 'OpenAI (OpenAIModel-56zaX)'                                                                      
                                     |    -> {'Text Input (TextInput-08dAi)': RunTree(id=UUID('7e39ff8f-0ab4-4702-b27e-4665669f6c41'),                   
                         name='Text Input (TextInput-08dAi)'...                                                                                          
                                     -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                   

                         KeyError: 'OpenAI (OpenAIModel-56zaX)'                                                                                          

                         ╭────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────╮               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py:177 in _end_traces   │               
                         │                                                                                                               │               
                         │   174 │   │   for tracer in self._tracers.values():                                                           │               
                         │   175 │   │   │   if tracer.ready:                                                                            │               
                         │   176 │   │   │   │   try:                                                                                    │               
                         │ ❱ 177 │   │   │   │   │   tracer.end_trace(                                                                   │               
                         │   178 │   │   │   │   │   │   trace_id=trace_id,                                                              │               
                         │   179 │   │   │   │   │   │   trace_name=trace_name,                                                          │               
                         │   180 │   │   │   │   │   │   outputs=self.outputs[trace_name],                                               │               
                         │                                                                                                               │               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py:128 in end_trace   │               
                         │                                                                                                               │               
                         │   125 │   ):                                                                                                  │               
                         │   126 │   │   if not self._ready:                                                                             │               
                         │   127 │   │   │   return                                                                                      │               
                         │ ❱ 128 │   │   child = self._children[trace_name]                                                              │               
                         │   129 │   │   raw_outputs = {}                                                                                │               
                         │   130 │   │   processed_outputs = {}                                                                          │               
                         │   131 │   │   if outputs:                                                                                     │               
                         ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯               
                         KeyError: 'OpenAI (OpenAIModel-56zaX)'                                                                                          
                ERROR    2024-11-08 03:55:56 - ERROR    - service - Error ending trace Tool Calling Agent (ToolCallingAgent-EeUMB)         service.py:185
                         Traceback (most recent call last):                                                                                              

                           File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap                                                              
                             self._bootstrap_inner()                                                                                                     
                             |    -> <function Thread._bootstrap_inner at 0x7f60057dfe20>                                                                
                             -> <Thread(asyncio_0, started 140049060447808)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner                                                       
                             self.run()                                                                                                                  
                             |    -> <function Thread.run at 0x7f60057dfb50>                                                                             
                             -> <Thread(asyncio_0, started 140049060447808)>                                                                             
                           File "/usr/lib/python3.10/threading.py", line 953, in run                                                                     
                             self._target(*self._args, **self._kwargs)                                                                                   
                             |    |        |    |        |    -> {}                                                                                      
                             |    |        |    |        -> <Thread(asyncio_0, started 140049060447808)>                                                 
                             |    |        |    -> (<weakref at 0x7f5fbc271990; to 'ThreadPoolExecutor' at 0x7f5fbc22ae90>,                              
                         <_queue.SimpleQueue object at 0x7f5fbc271620>, None,...                                                                         
                             |    |        -> <Thread(asyncio_0, started 140049060447808)>                                                               
                             |    -> <function _worker at 0x7f6002555750>                                                                                
                             -> <Thread(asyncio_0, started 140049060447808)>                                                                             
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83, in _worker                                                  
                             work_item.run()                                                                                                             
                             |         -> <function _WorkItem.run at 0x7f6002555870>                                                                     
                             -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedbd0>                                                           
                           File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                                      
                             result = self.fn(*self.args, **self.kwargs)                                                                                 
                                      |    |   |    |       |    -> {}                                                                                   
                                      |    |   |    |       -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedbd0>                            
                                      |    |   |    -> ()                                                                                                
                                      |    |   -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedbd0>                                         
                                      |    -> functools.partial(<built-in method run of _contextvars.Context object at 0x7f5f90e0b440>,                  
                         <bound method TracingService._end_t...                                                                                          
                                      -> <concurrent.futures.thread._WorkItem object at 0x7f5f79fedbd0>                                                  
                         > File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py", line 177, in                 
                         _end_traces                                                                                                                     
                             tracer.end_trace(                                                                                                           
                             |      -> <function LangSmithTracer.end_trace at 0x7f5ffc95c160>                                                            
                             -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                           
                           File "/langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py", line 128, in               
                         end_trace                                                                                                                       
                             child = self._children                                                                                                      
                                     |    |         -> 'Tool Calling Agent (ToolCallingAgent-EeUMB)'                                                     
                                     |    -> {'Text Input (TextInput-08dAi)': RunTree(id=UUID('7e39ff8f-0ab4-4702-b27e-4665669f6c41'),                   
                         name='Text Input (TextInput-08dAi)'...                                                                                          
                                     -> <langflow.services.tracing.langsmith.LangSmithTracer object at 0x7f5f793b0dc0>                                   

                         KeyError: 'Tool Calling Agent (ToolCallingAgent-EeUMB)'                                                                         

                         ╭────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────╮               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/service.py:177 in _end_traces   │               
                         │                                                                                                               │               
                         │   174 │   │   for tracer in self._tracers.values():                                                           │               
                         │   175 │   │   │   if tracer.ready:                                                                            │               
                         │   176 │   │   │   │   try:                                                                                    │               
                         │ ❱ 177 │   │   │   │   │   tracer.end_trace(                                                                   │               
                         │   178 │   │   │   │   │   │   trace_id=trace_id,                                                              │               
                         │   179 │   │   │   │   │   │   trace_name=trace_name,                                                          │               
                         │   180 │   │   │   │   │   │   outputs=self.outputs[trace_name],                                               │               
                         │                                                                                                               │               
                         │ /langflow/venv.19post2/lib/python3.10/site-packages/langflow/services/tracing/langsmith.py:128 in end_trace   │               
                         │                                                                                                               │               
                         │   125 │   ):                                                                                                  │               
                         │   126 │   │   if not self._ready:                                                                             │               
                         │   127 │   │   │   return                                                                                      │               
                         │ ❱ 128 │   │   child = self._children[trace_name]                                                              │               
                         │   129 │   │   raw_outputs = {}                                                                                │               
                         │   130 │   │   processed_outputs = {}                                                                          │               
                         │   131 │   │   if outputs:                                                                                     │               
                         ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯               
                         KeyError: 'Tool Calling Agent (ToolCallingAgent-EeUMB)'                                                                         

Entering new AgentExecutor chain... /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback [2024-11-08 03:55:56,323][WARNING] Error in callback coroutine: NotImplementedError('AgentAsyncHandler does not implement on_chat_model_start') /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback /usr/lib/python3.10/asyncio/base_events.py:688: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False> _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self) ResourceWarning: Enable tracemalloc to get the object allocation traceback The difference between chips and fries primarily depends on regional terminology. In the UK, "chips" refer to what is known as "fries" in the US. Chips are typically thicker and often served with fish and chips, while fries are usually thinner and can be served in various styles, such as crinkle-cut or shoestring. Additionally, chips in the UK can also refer to what Americans call "potato chips," which are thinly sliced and fried snacks.

Finished chain.

Expected behavior

Who can help?

No response

Operating System

MacOS Ventura 13.5.1

Langflow Version

1.0.19.post2

Python Version

3.10

Screenshot

https://prnt.sc/_dn5tkLiHKid

Flow File

https://prnt.sc/_dn5tkLiHKid

dosubot[bot] commented 3 weeks ago

The errors you're encountering with the "Tool Calling Agent" and "OpenAI Tools Agent" components in Langflow seem to be related to two main issues: KeyError in the tracing service and unclosed asyncio event loops.

  1. KeyError in Tracing Service: The KeyError occurs in the LangSmithTracer class when trying to end a trace that doesn't exist in the _children dictionary. This can happen if the trace name used in end_trace doesn't match any trace name previously added with add_trace. To resolve this, ensure that the trace names are consistent and correctly managed throughout the tracing process [1].

  2. Unclosed Event Loops: The ResourceWarning about unclosed event loops suggests that some asyncio event loops are not being properly closed. Langflow manages event loops by checking if the current loop is running and handling coroutines in separate threads if necessary. Ensure that all coroutines are awaited and that event loops are closed properly, especially when using asyncio.run or managing loops in threads [2].

  3. NotImplementedError in AgentAsyncHandler: The NotImplementedError for on_chat_model_start indicates that this method is not implemented in the AgentAsyncHandler class. This class is expected to handle various events, and you might need to implement this method if it's required for your use case [3].

To address these issues, you may need to review the flow setup and ensure that all necessary methods are implemented and that event loops are correctly managed.

To continue talking to Dosu, mention @dosu.

edwinjosechittilappilly commented 2 weeks ago

Hi @SavvySupport, thank you for the feedback. We have an upcoming release with enhanced agent capabilities. Please try to use the Agent Component in the upcoming release. I hope this will solve the issue.

edwinjosechittilappilly commented 1 week ago

I believe the issue has been resolved. If you encounter any further problems, please feel free to reopen the issue.