From 73a1c62cf49bb8a2bec3c3a52504f70d22f7bb43 Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 14:12:25 +0530 Subject: [PATCH 1/6] Removes agent decorator from agno --- plot_agent/agno_plot_agent/agent.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plot_agent/agno_plot_agent/agent.py b/plot_agent/agno_plot_agent/agent.py index 11a0b80..c27a210 100644 --- a/plot_agent/agno_plot_agent/agent.py +++ b/plot_agent/agno_plot_agent/agent.py @@ -10,7 +10,7 @@ from agno.utils.log import logger from dotenv import load_dotenv from traceloop.sdk import Traceloop -from traceloop.sdk.decorators import workflow, agent, task +from traceloop.sdk.decorators import workflow, task load_dotenv() @@ -37,7 +37,6 @@ class VisualizationRequest(BaseModel): title: Optional[str] = Field(None, description="Plot title.") hue: Optional[str] = Field(None, description="Column for color grouping.") -@agent(name="sql_and_plot_workflow") class SQLAndPlotWorkflow(Workflow): # SQL Agent that generates and executes Clickhouse queries sql_agent: Agent = Agent( From fe3ec8859fce06c2ef77c9a2163fc95e8da809e1 Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 14:18:31 +0530 Subject: [PATCH 2/6] Adds toolcalls --- plot_agent/agno_plot_agent/clickhouse_tools.py | 2 ++ plot_agent/agno_plot_agent/plot_tools.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plot_agent/agno_plot_agent/clickhouse_tools.py b/plot_agent/agno_plot_agent/clickhouse_tools.py index 18a04cc..5e1d21c 100644 --- a/plot_agent/agno_plot_agent/clickhouse_tools.py +++ b/plot_agent/agno_plot_agent/clickhouse_tools.py @@ -5,7 +5,9 @@ from agno.utils.log import logger import os from dotenv import load_dotenv +from traceloop.sdk.decorators import tool +@tool(name="clickhouse_tools") class ClickHouseTools(Toolkit): def __init__(self): super().__init__(name="clickhouse_tools") diff --git a/plot_agent/agno_plot_agent/plot_tools.py b/plot_agent/agno_plot_agent/plot_tools.py index ce1035c..0291fe4 100644 --- a/plot_agent/agno_plot_agent/plot_tools.py +++ b/plot_agent/agno_plot_agent/plot_tools.py @@ -9,11 +9,13 @@ import os import uuid from matplotlib.ticker import FuncFormatter +from traceloop.sdk.decorators import tool # Create plots directory if it doesn't exist PLOTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plots") os.makedirs(PLOTS_DIR, exist_ok=True) +@tool(name="plot_tools") class PlotTools(Toolkit): def __init__(self): super().__init__(name="plot_tools") From 257bd06efcae7e8b5af8d62a6337f014d0d46131 Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 14:31:40 +0530 Subject: [PATCH 3/6] Adding an agent decorator --- plot_agent/agno_plot_agent/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plot_agent/agno_plot_agent/api.py b/plot_agent/agno_plot_agent/api.py index bc2d486..5d30446 100644 --- a/plot_agent/agno_plot_agent/api.py +++ b/plot_agent/agno_plot_agent/api.py @@ -7,6 +7,7 @@ import uuid from agent import SQLAndPlotWorkflow, PlotResult from agno.utils.log import logger +from traceloop.sdk.decorators import agent # Create plots directory if it doesn't exist PLOTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plots") @@ -120,6 +121,7 @@ async def get_plot(job_id: str): return FileResponse(plot_path) +@agent(name="process_query") async def process_query(job_id: str, query: str): """ Process the query in the background and update the results store. From 8d85e39ffd8527319471db9dae43f454a8e028c3 Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 14:36:42 +0530 Subject: [PATCH 4/6] Adds plot agent --- plot_agent/agno_plot_agent/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plot_agent/agno_plot_agent/api.py b/plot_agent/agno_plot_agent/api.py index 5d30446..61c2a9d 100644 --- a/plot_agent/agno_plot_agent/api.py +++ b/plot_agent/agno_plot_agent/api.py @@ -91,6 +91,7 @@ async def get_job_status(job_id: str): ) @app.get("/plot/{job_id}") +@agent(name="get_plot") async def get_plot(job_id: str): """ Get the plot image for a completed job. From 6b396032ddfe6571992bea79866660c56cfb2a2c Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 15:01:12 +0530 Subject: [PATCH 5/6] Agents separation --- plot_agent/agno_plot_agent/agent.py | 25 +++++++++++++++---------- plot_agent/agno_plot_agent/api.py | 2 -- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plot_agent/agno_plot_agent/agent.py b/plot_agent/agno_plot_agent/agent.py index c27a210..4a3845a 100644 --- a/plot_agent/agno_plot_agent/agent.py +++ b/plot_agent/agno_plot_agent/agent.py @@ -10,7 +10,7 @@ from agno.utils.log import logger from dotenv import load_dotenv from traceloop.sdk import Traceloop -from traceloop.sdk.decorators import workflow, task +from traceloop.sdk.decorators import workflow, task, agent load_dotenv() @@ -37,9 +37,10 @@ class VisualizationRequest(BaseModel): title: Optional[str] = Field(None, description="Plot title.") hue: Optional[str] = Field(None, description="Column for color grouping.") -class SQLAndPlotWorkflow(Workflow): - # SQL Agent that generates and executes Clickhouse queries - sql_agent: Agent = Agent( +@agent(name="sql_agent") +def create_sql_agent() -> Agent: + """Creates and returns a SQL agent for generating and executing Clickhouse queries.""" + return Agent( model=OpenAIChat(id="openai-main/gpt-4o", api_key=os.getenv("LLM_GATEWAY_API_KEY"), base_url=os.getenv("LLM_GATEWAY_BASE_URL")), description="You are an expert in generating and executing Clickhouse SQL queries from user queries in English.", instructions=[ @@ -67,7 +68,7 @@ class SQLAndPlotWorkflow(Workflow): "- applied_configs: Map(LowCardinality(String), Map(LowCardinality(String), String)): Configuration settings applied to the request.", "- created_at: DateTime64(9) Delta(8), ZSTD(1): The timestamp when the request was made.", "Clickhouse has slighlty different syntax rules than MySQL or PostgreSQL. Please make sure to use the correct syntax for Clickhouse." - "Syntax rule: Use toIntervalXXX(N) (e.g., toIntervalDay(30)) instead of INTERVAL N UNIT (e.g., INTERVAL 30 DAY) for interval arithmetic in ClickHouse." + "Syntax rule: Use toIntervalXXX(N) (e.g., toIntervalDay(30)) instead of INTERVAL N UNIT (e.g., INTERVAL 30 DAY) for interval arithmetic in ClickHouse.", "Syntax rule: Do not end in a semicolon (;) in the query. Only end with a newline.", ], tools=[ClickHouseTools()], @@ -75,11 +76,12 @@ class SQLAndPlotWorkflow(Workflow): markdown=True, response_model=SQLQueryResult, structured_outputs=True, - # debug_mode=True, ) - # Plot Agent that creates visualizations - plot_agent: Agent = Agent( +@agent(name="plot_agent") +def create_plot_agent() -> Agent: + """Creates and returns a Plot agent for creating data visualizations.""" + return Agent( model=OpenAIChat(id="openai-main/gpt-4o", api_key=os.getenv("LLM_GATEWAY_API_KEY"), base_url=os.getenv("LLM_GATEWAY_BASE_URL")), description="You are an expert in creating data visualizations from SQL query results.", instructions=[ @@ -102,10 +104,13 @@ class SQLAndPlotWorkflow(Workflow): show_tool_calls=True, markdown=True, response_model=VisualizationRequest, - # structured_outputs=True, - # debug_mode=True, ) +class SQLAndPlotWorkflow(Workflow): + def __init__(self): + super().__init__() + self.sql_agent = create_sql_agent() + self.plot_agent = create_plot_agent() @workflow(name="plotting workflow") def run_workflow(self, query: str) -> Iterator[RunResponse]: diff --git a/plot_agent/agno_plot_agent/api.py b/plot_agent/agno_plot_agent/api.py index 61c2a9d..b23002d 100644 --- a/plot_agent/agno_plot_agent/api.py +++ b/plot_agent/agno_plot_agent/api.py @@ -91,7 +91,6 @@ async def get_job_status(job_id: str): ) @app.get("/plot/{job_id}") -@agent(name="get_plot") async def get_plot(job_id: str): """ Get the plot image for a completed job. @@ -122,7 +121,6 @@ async def get_plot(job_id: str): return FileResponse(plot_path) -@agent(name="process_query") async def process_query(job_id: str, query: str): """ Process the query in the background and update the results store. From ea9bb48c84ec7b791c00e78cbcae95967e476b05 Mon Sep 17 00:00:00 2001 From: sateesh Date: Wed, 7 May 2025 15:09:45 +0530 Subject: [PATCH 6/6] Removes agents tracing --- plot_agent/agno_plot_agent/agent.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plot_agent/agno_plot_agent/agent.py b/plot_agent/agno_plot_agent/agent.py index 4a3845a..1da420a 100644 --- a/plot_agent/agno_plot_agent/agent.py +++ b/plot_agent/agno_plot_agent/agent.py @@ -10,7 +10,7 @@ from agno.utils.log import logger from dotenv import load_dotenv from traceloop.sdk import Traceloop -from traceloop.sdk.decorators import workflow, task, agent +from traceloop.sdk.decorators import workflow, task load_dotenv() @@ -37,7 +37,6 @@ class VisualizationRequest(BaseModel): title: Optional[str] = Field(None, description="Plot title.") hue: Optional[str] = Field(None, description="Column for color grouping.") -@agent(name="sql_agent") def create_sql_agent() -> Agent: """Creates and returns a SQL agent for generating and executing Clickhouse queries.""" return Agent( @@ -78,7 +77,6 @@ def create_sql_agent() -> Agent: structured_outputs=True, ) -@agent(name="plot_agent") def create_plot_agent() -> Agent: """Creates and returns a Plot agent for creating data visualizations.""" return Agent(