Skip to content
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

Error on asking follow up questions in Workflow. *TypeError: cannot pickle 'psycopg2.extensions.connection' object* #1667

Open
alaap001 opened this issue Dec 31, 2024 · 3 comments

Comments

@alaap001
Copy link

alaap001 commented Dec 31, 2024

Hey, thanks for the amazing work.

I am working on a Workflow application, and when using Playground with workflow, I get this error when asking for the second question after the first.
Ig it is likely cz of the psycopg2 connection when working with db and everytime I ask a question it seems to establish a connection causing some issue, can you please let me know what is going wrong and possible solution around workflow chatting?

Error

INFO:     Will watch for changes in these directories: ['/media/alaap/Windows/OldLinux/k_files/LLM/phiData/phidata']
INFO:     Uvicorn running on http://localhost:7777 (Press CTRL+C to quit)
INFO:     Started reloader process [217762] using WatchFiles
WARNING:  WatchFiles detected changes in 'kgpt/sql_analysis_workflow.py'. Reloading...
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 1edbd6c4-2239-46df-a925-542310a3d778 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 2ace1a14-5d8a-4187-81e9-cf1a0ce58dcd ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: acb96058-8126-447e-93bb-2ef605f21c33 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 35b04848-0d0e-4a75-805c-4ae1548a0b2a ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Worfklow ID: 8a051803-6f97-4e32-80af-a57f84db8fc2 ***********                                                                                                                                                                      
DEBUG    *********** Worflow Session ID: dece537f-2c23-4637-bc98-3203315d15e4 ***********                                                                                                                                                               
INFO:     Started server process [218081]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:49706 - "OPTIONS /v1/playground/status HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/status HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "OPTIONS /v1/playground/agent/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/agent/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/status HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "OPTIONS /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/status HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/agent/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/status HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:49706 - "GET /v1/playground/workflows/get HTTP/1.1" 200 OK
INFO:     127.0.0.1:42270 - "OPTIONS /v1/playground/workflow/inputs/37382748-a5c3-4fb9-8278-0c6988e98174 HTTP/1.1" 200 OK
INFO:     127.0.0.1:42272 - "OPTIONS /v1/playground/workflow/config/37382748-a5c3-4fb9-8278-0c6988e98174 HTTP/1.1" 200 OK
INFO:     127.0.0.1:42294 - "OPTIONS /v1/playground/workflow/37382748-a5c3-4fb9-8278-0c6988e98174/session/all HTTP/1.1" 200 OK
INFO:     127.0.0.1:42270 - "GET /v1/playground/workflow/inputs/37382748-a5c3-4fb9-8278-0c6988e98174 HTTP/1.1" 200 OK
INFO:     127.0.0.1:42272 - "GET /v1/playground/workflow/config/37382748-a5c3-4fb9-8278-0c6988e98174 HTTP/1.1" 200 OK
INFO:     127.0.0.1:42294 - "POST /v1/playground/workflow/37382748-a5c3-4fb9-8278-0c6988e98174/session/all HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:42270 - "GET /v1/playground/workflow/config/37382748-a5c3-4fb9-8278-0c6988e98174 HTTP/1.1" 200 OK
INFO:     127.0.0.1:44454 - "OPTIONS /v1/playground/workflow/37382748-a5c3-4fb9-8278-0c6988e98174/run HTTP/1.1" 200 OK
sql_query='SELECT OP AS Operator, AVG(accuracy_normalized) AS Average_Accuracy FROM BA GROUP BY OP ORDER BY Average_Accuracy DESC LIMIT 5;'

Attempt 1 - Executing query:
sql_query='SELECT OP AS Operator, AVG(accuracy_normalized) AS Average_Accuracy FROM BA GROUP BY OP ORDER BY Average_Accuracy DESC LIMIT 5;'
INFO     Running: SELECT OP AS Operator, AVG(accuracy_normalized) AS Average_Accuracy FROM BA GROUP BY OP ORDER BY Average_Accuracy DESC LIMIT 5                                                                      
INFO:     127.0.0.1:44454 - "POST /v1/playground/workflow/37382748-a5c3-4fb9-8278-0c6988e98174/run HTTP/1.1" 200 OK
INFO:     127.0.0.1:53374 - "POST /v1/playground/workflow/37382748-a5c3-4fb9-8278-0c6988e98174/run HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/middleware/cors.py", line 93, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/middleware/cors.py", line 144, in simple_response
    await self.app(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/phi/playground/router.py", line 557, in run_workflow
    new_workflow_instance = workflow.deep_copy(update={"workflow_id": workflow_id})
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/phi/workflow/workflow.py", line 410, in deep_copy
    new_workflow = self.__class__(**fields_for_new_workflow)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/phi/workflow/workflow.py", line 312, in __init__
    super().__init__(**data)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/pydantic/main.py", line 212, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 153, in deepcopy
    y = copier(memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/site-packages/pydantic/main.py", line 805, in __deepcopy__
    _object_setattr(m, '__dict__', deepcopy(self.__dict__, memo=memo))
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 206, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/alaap/miniconda3/envs/envPy310/lib/python3.10/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'psycopg2.extensions.connection' object

Code


"""SQL Analysis Workflow that uses a team of agents to analyze database queries."""

from typing import List, Dict, Any, Optional, ClassVar
from pydantic import BaseModel, Field
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.workflow.workflow import Workflow
from phi.tools.postgres import PostgresTools
from phi.run.response import RunResponse
from phi.utils.pprint import pprint_run_response
from phi.knowledge.csv import CSVKnowledgeBase
from phi.vectordb.pgvector import PgVector
from phi.vectordb.search import SearchType
from phi.embedder.openai import OpenAIEmbedder
import json
from phi.model.groq import Groq
from reranker import BGEFlagReranker
from phi.model.ollama import Ollama
from dotenv import load_dotenv
from phi.embedder.ollama import OllamaEmbedder

load_dotenv()


class SQLQuery(BaseModel):
    query: str = Field(description="The SQL query to execute")


class SQLAnalysisResult(BaseModel):
    sql: str = Field(description="The SQL query that was executed")
    data: str = Field(description="Data returned from query")
    analysis: str = Field(description="Analysis considering the question and returned data")


class SQLAnalysisWorkflow(Workflow):
    description: str = "SQL Analysis Workflow"

    reranker: ClassVar[BGEFlagReranker] = BGEFlagReranker(model_name="BAAI/bge-reranker-large")

    # Initialize knowledge base
    knowledge_base: CSVKnowledgeBase = CSVKnowledgeBase(
        path="knowledge",
        num_documents=10,
        reranker=reranker,
        vector_db=PgVector(
            table_name="sql_knowledge",
            db_url="postgresql+psycopg://ai:ai@localhost:5432/ai",
            search_type=SearchType.hybrid,
            embedder=OllamaEmbedder(model="mxbai-embed-large",dimensions=1024)
        )
    )

    # knowledge_base.load(recreate=True, upsert=True)

    # Initialize PostgresTools
    target_db: PostgresTools = PostgresTools(
        {detalis}
        run_queries=True,
        inspect_queries=True,
        summarize_tables=True
    )

    # Define agents as class attributes
    query_generator: Agent = Agent(
        name="SQL Query Generator",
        description="Generate SQL queries based on natural language questions",
       
        instructions=[
            "You are an expert SQL query generator.",
            # "search the knowledge base for similar questions and their SQL queries.",
            
          
        ],
        tools=[target_db],
        debug_mode=True,
        show_tool_calls=True,
        model=Ollama(id="qwen2.5:72b-instruct"),
        # model=OpenAIChat(id="gpt-4o-mini"),
        response_model=SQLQuery,
        structured_outputs=True,
    )

    data_analyzer: Agent = Agent(
        name="Data Analyst",
        description="Analyze query results and provide insights",
        system_prompt="""You are an expert data analyst. Your role is to analyze SQL query results and provide meaningful insights from the data and question asked.""",
        instructions=[
            "You are an expert data analyst.",
            
        ],
        knowledge=knowledge_base,
        search_knowledge=True,
        debug_mode=True,
        show_tool_calls=True,
        model=Ollama(id="qwen2.5:72b-instruct"),
        markdown=True,
    )

    def is_error_message(self, result: str) -> bool:
        """Check if the result is an error message"""
        error_indicators = [
            "syntax error",
            "does not exist",
            "column",
            "relation",
            "ERROR:",
            "error",
            "invalid",
            "cannot"
        ]
        return any(indicator.lower() in result.lower() for indicator in error_indicators)

    def run(self, question: str) -> RunResponse:
        # Generate SQL Query
        query_response = self.query_generator.run(question)
        sql_query = query_response.content.query

        # Try executing with error handling and fixing
        max_tries = 3
        attempt = 1
        
        while attempt <= max_tries:
            print(f"\nAttempt {attempt} - Executing query:")
            print(f"{sql_query=}")
            
            # Execute query
            results = self.target_db.run_query(sql_query)
            
            # Check if results contain an error message
            if not self.is_error_message(results):
                # Query succeeded
                analysis_input = f"""
                Original Question: {question}
                
                Query Used:
                {sql_query}
                
                Query Results:
                {results}
                
                Please analyze these results in context of the original question.
                Focus on key insights and patterns in the data.
                """
                analysis = self.data_analyzer.run(analysis_input)
                
                result = SQLAnalysisResult(
                    sql=sql_query,
                    data=results,
                    analysis=analysis.content
                )
                return RunResponse(content=json.dumps(result.dict(), indent=2))
            
            # Query failed, try to fix it
            if attempt < max_tries:
                print(f"Error: {results}")
                
                
            else:
                # All attempts failed
                result = SQLAnalysisResult(
                    sql=sql_query,
                    data="",
                    analysis=f"Failed to execute query after {max_tries} attempts. Last error: {results}"
                )
                return RunResponse(content=json.dumps(result.model_dump(), indent=2))


if __name__ == "__main__":
    from rich.prompt import Prompt

    # Get question from user
    question = Prompt.ask(
        "[bold]Enter your SQL analysis question[/bold]\n✨",
        default="Who are my most efficient operators ?"
    )
    
    # Initialize workflow
    workflow = SQLAnalysisWorkflow()
    
    # Run workflow and get results
    response = workflow.run(question)
    result = json.loads(response.content)
    
    # Print formatted results using pprint_run_response
    markdown_content = (
        f"## SQL Query\n"
        f"```sql\n{result['sql']}\n```\n\n"
        f"## Data\n"
        f"```\n{result['data']}\n```\n\n"
        f"## Analysis\n"
        f"{result['analysis']}"
    )
    pprint_run_response(RunResponse(content=markdown_content), markdown=True)

and playground.py

"""
1. Install dependencies using: `pip install openai sqlalchemy 'fastapi[standard]' phidata`
2. Run the script using: `python cookbook/workflows/sql_playground.py`
"""

from phi.playground import Playground, serve_playground_app
from phi.storage.workflow.sqlite import SqlWorkflowStorage

# Import the workflow
from sql_analysis_workflow import SQLAnalysisWorkflow  # type: ignore
from phi.tools.postgres import PostgresTools


# Initialize the workflow with SQLite storage
sql_analysis = SQLAnalysisWorkflow(
    workflow_id="sql-analysis",
    storage=SqlWorkflowStorage(
        table_name="sql_analysis_workflows",
        db_file="tmp/workflows.db",
    ),
)

# Initialize the Playground with the workflow
app = Playground(
    workflows=[sql_analysis]
).get_app()

if __name__ == "__main__":
    serve_playground_app("sql_playground:app", reload=True)
@manthanguptaa
Copy link
Contributor

Hey @alaap001! Are you still facing this issue?

@alaap001
Copy link
Author

alaap001 commented Jan 6, 2025

Hey @manthanguptaa, hope you're doing well.

I found a workaround but it doesn't solve the problem and I am not very happy with it.

I moved postgres and other agent initialization in the init function of my workflow class. It works but it initialize new Workflow session everytime a question is asked, which means it has absolutely 0 idea of the last message asked which means it won't work good as a chatbot workflow agent.

Here are the working logs for reference:

DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: bfd0730e-97b3-424d-9fab-6b8926d05634 | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: 2943c8ea-7abd-4774-93d1-07ce83515a2f ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 2943c8ea-7abd-4774-93d1-07ce83515a2f | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: 1eff0ac1-807e-464a-ba92-de7fe091d3c6 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 1eff0ac1-807e-464a-ba92-de7fe091d3c6 | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    Initialized PgVector with table 'ai.sql_knowledge'                                                                                                                                                                                             
DEBUG    Function: show_tables registered with postgres_tools                                                                                                                                                                                           
DEBUG    Function: describe_table registered with postgres_tools                                                                                                                                                                                        
DEBUG    Function: inspect_query registered with postgres_tools                                                                                                                                                                                         
DEBUG    Function: run_query registered with postgres_tools                                                                                                                                                                                             
DEBUG    Function: summarize_table registered with postgres_tools                                                                                                                                                                                       
DEBUG    *********** Agent ID: d5b895e9-b2d5-4993-9089-470df4093d85 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 4a363274-043a-4afa-aed8-b5ec9a6c2449 ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 13ba1c7a-06b1-481e-9986-6d3db6213428 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 31f5a21d-6d7f-416d-a972-20de7dc5741a ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 0819ea85-aa2d-4d3a-b667-3b9fcea7a584 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: ea6a70ad-7c7d-42a2-8c13-8d8d5bedabbd ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Worfklow ID: sql-analysis ***********                                                                                                                                                                                              
DEBUG    *********** Worflow Session ID: ebe2e24c-72d7-4c55-b816-8a9eaf9491b8 ***********                                                                                                                                                               
sql_query='SELECT operator_name AS Operator, SUM(total_picking_time) AS Total_Picking_Time,Efficiency_Percentage DESC LIMIT 5;'

Attempt 1 - Executing query:
sql_query='SELECT operator_name AS Operator, SUM(total_picking_time) AS Total_Picking_Time,Efficiency_Percentage DESC LIMIT 5;'

INFO:     127.0.0.1:52726 - "POST /v1/playground/workflow/sql-analysis/run HTTP/1.1" 200 OK
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 9a8e5547-fb7f-4b86-9371-ebbb49ed0fcb | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: 2504db7d-1248-44ba-8f45-c99a3b27b9c9 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 2504db7d-1248-44ba-8f45-c99a3b27b9c9 | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: 7086dd7f-aab3-4788-b4d4-478f70d1865f ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 7086dd7f-aab3-4788-b4d4-478f70d1865f | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    Initialized PgVector with table 'ai.sql_knowledge'                                                                                                                                                                                             
DEBUG    Function: show_tables registered with postgres_tools                                                                                                                                                                                           
DEBUG    Function: describe_table registered with postgres_tools                                                                                                                                                                                        
DEBUG    Function: inspect_query registered with postgres_tools                                                                                                                                                                                         
DEBUG    Function: run_query registered with postgres_tools                                                                                                                                                                                             
DEBUG    Function: summarize_table registered with postgres_tools                                                                                                                                                                                       
DEBUG    *********** Agent ID: f077adec-6d1c-4086-9fea-0a72e451b5a5 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: d0212763-e3c0-4ff7-8d3b-628601d296c3 ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 3f9c7df5-d6e8-40b8-a6cd-f7086668c091 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: c1264fde-fbae-4fde-bd52-234c3080132b ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 46153da3-bee1-439d-a2cd-c7d1e2a717cc ***********                                                                                                                                                                         
DEBUG    *********** Session ID: e02757e1-a710-4b42-a7ee-9e66136761fc ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Worfklow ID: sql-analysis ***********                                                                                                                                                                                              
DEBUG    *********** Worflow Session ID: 685e9e2c-2320-4abf-91de-d3ae574a2cd8 ***********                                                                                                                                                               
sql_query='SELECT AVG(setup_time) AS Average_Case_Setup_Time FROM case_activity;'

Attempt 1 - Executing query:
sql_query='SELECT AVG(setup_time) AS Average_Case_Setup_Time FROM case_activity;'
INFO     Running: SELECT AVG(setup_time) AS Average_Case_Setup_Time FROM case_activity LIMIT 30                                                                                                                                                         
INFO:     127.0.0.1:46282 - "POST /v1/playground/workflow/sql-analysis/run HTTP/1.1" 200 OK
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 1a2b1962-263f-4df6-81b1-73863b609b0f | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: ea3d99da-c361-470b-acff-6d52fe54f5c9 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: ea3d99da-c361-470b-acff-6d52fe54f5c9 | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    *********** Agent ID: 4fa72ef9-2629-4f36-8cad-f6bd56fa25f3 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 996cbaf7-39e9-404c-b02a-57cbf7f4084d ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    Created new Agent: agent_id: 4fa72ef9-2629-4f36-8cad-f6bd56fa25f3 | session_id: 996cbaf7-39e9-404c-b02a-57cbf7f4084d                                                                                                                           
DEBUG    Initialized PgVector with table 'ai.sql_knowledge'                                                                                                                                                                                             
DEBUG    Function: show_tables registered with postgres_tools                                                                                                                                                                                           
DEBUG    Function: describe_table registered with postgres_tools                                                                                                                                                                                        
DEBUG    Function: inspect_query registered with postgres_tools                                                                                                                                                                                         
DEBUG    Function: run_query registered with postgres_tools                                                                                                                                                                                             
DEBUG    Function: summarize_table registered with postgres_tools                                                                                                                                                                                       
DEBUG    *********** Agent ID: 20efe344-e400-4ff8-ad69-51d4b6d77a72 ***********                                                                                                                                                                         
DEBUG    *********** Session ID: de3f735c-173d-4a93-ba75-3978b0e736d3 ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: cb0f2509-5682-401e-a1d1-c652bd41952c ***********                                                                                                                                                                         
DEBUG    *********** Session ID: a66fa601-6da1-4f6e-8a79-e7af00d3ea6b ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Agent ID: 5c90f99e-a512-49cc-a12c-b952988dee3f ***********                                                                                                                                                                         
DEBUG    *********** Session ID: 298e0834-7114-4888-8645-7658d92162eb ***********                                                                                                                                                                       
DEBUG    Debug logs enabled                                                                                                                                                                                                                             
DEBUG    *********** Worfklow ID: sql-analysis ***********                                                                                                                                                                                              

This isn't the ideal solution, can you please have a brief look at the above attached code and see what could cause users issue when working with continuation messages in workflow with db tools?

@manthanguptaa
Copy link
Contributor

@alaap001 sorry for the late reply. We are working on a new release and this will be fixed in that one. It will take a little more time than I had like but the fix should be out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants