<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Best Architecture for Building a Custom Agent in Databricks? in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174165#M2233</link>
    <description>&lt;P&gt;For this workflow, the recommended Databricks architecture is to use Mosaic AI Agent Framework ("Code Your Own Agent") deployed via Model Serving, paired with Databricks Apps for the user UI (since Genie Spaces cannot process custom log-parsing Python logic). For your functions, adopt a hybrid approach: convert structured metric/cost queries into Unity Catalog Functions for governance and reusability, but keep the event log parsing logic inside your Agent Code Tools, as Unity Catalog UDFs face environment limits and payload caps when reading raw files from UC Volumes.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Oct 2026 11:33:51 GMT</pubDate>
    <dc:creator>marie699wood</dc:creator>
    <dc:date>2026-10-21T11:33:51Z</dc:date>
    <item>
      <title>Best Architecture for Building a Custom Agent in Databricks?</title>
      <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174102#M2229</link>
      <description>&lt;DIV&gt;&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;I'm building a Databricks cost optimization agent and would appreciate some guidance on the recommended architecture.&lt;/P&gt;&lt;P&gt;My current design consists of the following functions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Retrieve the last N job runs along with cost, DBU usage, runtime, cluster configuration, and worker information.&lt;/LI&gt;&lt;LI&gt;Read and analyze Spark event logs from Compute Log Delivery stored in a Unity Catalog Volume.&lt;/LI&gt;&lt;LI&gt;Combine historical run metrics and Spark event metrics into a consolidated dataset for analysis.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;My goal is for a user to ask questions such as:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"Analyze job_id &amp;lt;job_id&amp;gt; and recommend cost optimizations."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The agent would analyze up to the last 50 runs (or however many runs have logs available), evaluate cost, utilization, shuffle, spills, executor usage, memory, etc., and then generate optimization recommendations.&lt;/P&gt;&lt;P&gt;My functions are currently implemented as Python functions and are &lt;STRONG&gt;not Unity Catalog Functions&lt;/STRONG&gt;. Given this use case:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is it better to build this using &lt;STRONG&gt;Agent Framework (Code Your Own Agent)&lt;/STRONG&gt;?&lt;/LI&gt;&lt;LI&gt;Should I convert some or all of these functions into UC Functions?&lt;/LI&gt;&lt;LI&gt;Would a &lt;STRONG&gt;Genie Space&lt;/STRONG&gt;, &lt;STRONG&gt;Agent Framework&lt;/STRONG&gt;, or &lt;STRONG&gt;Databricks Apps&lt;/STRONG&gt; be the recommended architecture for this type of cost optimization agent?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I'm interested in understanding Databricks best practices for building an agent that needs to orchestrate Python logic, inspect Spark event logs, and generate recommendations using an LLM.&lt;/P&gt;&lt;P&gt;Thanks in advance for any recommendations or design suggestions.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 20 Oct 2026 21:57:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174102#M2229</guid>
      <dc:creator>Vamsi3757</dc:creator>
      <dc:date>2026-10-20T21:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Best Architecture for Building a Custom Agent in Databricks?</title>
      <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174165#M2233</link>
      <description>&lt;P&gt;For this workflow, the recommended Databricks architecture is to use Mosaic AI Agent Framework ("Code Your Own Agent") deployed via Model Serving, paired with Databricks Apps for the user UI (since Genie Spaces cannot process custom log-parsing Python logic). For your functions, adopt a hybrid approach: convert structured metric/cost queries into Unity Catalog Functions for governance and reusability, but keep the event log parsing logic inside your Agent Code Tools, as Unity Catalog UDFs face environment limits and payload caps when reading raw files from UC Volumes.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2026 11:33:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174165#M2233</guid>
      <dc:creator>marie699wood</dc:creator>
      <dc:date>2026-10-21T11:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Best Architecture for Building a Custom Agent in Databricks?</title>
      <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174176#M2235</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Recommendation: use a custom code agent, deployed on Databricks Apps/Agent Runtime.&lt;/STRONG&gt;&lt;/P&gt;
&lt;H3&gt;Suggested architecture&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Precompute the data&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Parse Spark event logs asynchronously from the UC Volume.&lt;/LI&gt;
&lt;LI&gt;Store normalized run-level and stage-level metrics in Delta tables.&lt;/LI&gt;
&lt;LI&gt;Avoid reparsing raw event logs during every user request.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Use a custom agent for orchestration&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Keep the Python tools for log parsing, metric aggregation, and recommendation logic.&lt;/LI&gt;
&lt;LI&gt;The agent should call deterministic tools, compare metrics against thresholds, and use the LLM mainly to explain findings and recommendations.&lt;/LI&gt;
&lt;LI&gt;Databricks supports custom Python tools directly in code-first agents.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Use Unity Catalog Functions selectively&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Convert stable, parameterized, reusable logic—such as &lt;CODE&gt;get_job_runs(job_id, limit)&lt;/CODE&gt; or &lt;CODE&gt;get_run_metrics(run_id)&lt;/CODE&gt;—into UC Functions.&lt;/LI&gt;
&lt;LI&gt;Do not force complex Spark-log parsing or dependency-heavy code into UC Functions.&lt;/LI&gt;
&lt;LI&gt;UC Functions are appropriate for predefined, governed logic exposed as agent tools.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Use Genie only as an optional interface&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Genie is a good fit for natural-language analysis over the curated Delta tables.&lt;/LI&gt;
&lt;LI&gt;It is not the best primary orchestrator for raw log inspection, custom Python execution, and multi-step analysis. Chat mode is focused on structured data and single-query questions.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Use Databricks Apps for delivery&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Apps provide the user-facing UI, authentication, and hosting layer; the custom agent remains the orchestration layer.&lt;/LI&gt;
&lt;LI&gt;For new agents, Databricks recommends the current Agent Runtime/Agent Bricks path rather than legacy agent-server templates.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;Pattern:&lt;/STRONG&gt;&lt;BR /&gt;&lt;CODE&gt;Databricks App → Custom Agent → Python tools + UC Functions → Delta metrics tables&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;This provides the flexibility needed for Spark analysis while retaining Unity Catalog governance, MLflow tracing, and a path to evaluation and production deployment.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2026 14:51:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174176#M2235</guid>
      <dc:creator>Lu_Wang_ENB_DBX</dc:creator>
      <dc:date>2026-10-21T14:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Best Architecture for Building a Custom Agent in Databricks?</title>
      <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174266#M2237</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/232022"&gt;@Vamsi3757&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I experimented with a similar use case recently and built a working Spark job cost/performance optimization agent in Databricks.&lt;/P&gt;&lt;P&gt;I used a custom Python tool-calling agent with &lt;STRONG&gt;databricks-gpt-oss-120b&lt;/STRONG&gt; through Databricks Model Serving, hosted as a Databricks App. I've attached the simplified architecture diagram for reference.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data_pulse_0-1792654350399.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/32447iBCB4D9D2AFD0EDBA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="data_pulse_0-1792654350399.png" alt="data_pulse_0-1792654350399.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;A few observations from the implementation:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Python tool orchestration:&lt;/STRONG&gt; Exposed existing Python diagnostic logic directly as tools for retrieving job metrics, detecting anomalies, inspecting query history, and optionally analysing Spark event logs. The LLM dynamically selects tools, while Python validates and executes the calls. This worked without requiring LangGraph or converting the functions into Unity Catalog functions.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Native system tables&lt;/STRONG&gt;: Used&lt;EM&gt; system.lakeflow.job_run_timeline, system.billing.usage, system.billing.list_prices, and system.query.history&lt;/EM&gt; for run history, DBUs, estimated costs, and SQL execution metrics. These helps to gather all Job run time history, Cost, Queries ran as part of it.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Evidence-based recommendations&lt;/STRONG&gt;: Implemented runtime/DBU anomaly detection using historical baselines, with safeguards for insufficient data. The agent distinguishes observations from possible causes and suggests further investigation rather than assuming a root cause.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Spark-level diagnostics:&lt;/STRONG&gt; In a separate Photon shuffle experiment, Query Profile showed 70.5 MB of local shuffle activity, while &lt;EM&gt;system.query.history.shuffle_read_bytes&lt;/EM&gt; reported zero network shuffle. This highlights why query level metrics alone may not capture all Spark execution details.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Spark event logs:&lt;/STRONG&gt; Implemented Python parsing for stage/task-level diagnostics, currently validated with synthetic event-log fixtures.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Conversational context&lt;/STRONG&gt;: The deployed agent successfully handled follow up questions using previously validated evidence without necessarily re-executing all the diagnostic tools.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My takeaway:&lt;/STRONG&gt; For this use case, a lightweight custom Python tool-calling agent is a practical starting point. Keep the diagnostic functions modular, use native system tables for historical cost/performance analysis and invoke detailed Spark event-log analysis selectively when available.&lt;/P&gt;&lt;P&gt;Genie could complement this for conversational exploration of curated metrics, but isn't essential for orchestrating Python diagnostic tools.&lt;/P&gt;&lt;P&gt;Below is from the App and its response.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data_pulse_1-1792654665167.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/32448i17A48821DA3442DA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="data_pulse_1-1792654665167.png" alt="data_pulse_1-1792654665167.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps and give some more insights. All the best for your implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2026 07:42:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174266#M2237</guid>
      <dc:creator>data_pulse</dc:creator>
      <dc:date>2026-10-22T07:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Best Architecture for Building a Custom Agent in Databricks?</title>
      <link>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174901#M2246</link>
      <description>&lt;P&gt;Agent Framework for the agent, UC Functions for the reads, a Delta table for the event logs&lt;/P&gt;&lt;P&gt;I'd go with a code-your-own agent in Agent Framework, but I'd move most of the heavy lifting out of the agent loop.&lt;/P&gt;&lt;P&gt;1. Parse the Spark event logs in a scheduled job, not inside a tool. Event logs for 50 runs can be large, and parsing them at question time makes the agent slow and the token count unpredictable. A job that reads the Compute Log Delivery files from the Volume and writes one row per run (or per stage) with shuffle read/write, spill to memory/disk, executor count, peak memory, task skew and GC time turns the analysis into a table query.&lt;/P&gt;&lt;P&gt;2. Make the read tools UC Functions. Once the event metrics live in Delta, "get last N runs" and "get event metrics for job_id" become simple SQL functions over system.lakeflow.job_run_timeline, system.billing.usage (usage_metadata.job_id / job_run_id), system.compute.clusters and your event table. As UC Functions they're governed, reusable from Playground, Genie or another agent, and easy to test on their own. Keep plain Python only where a tool really needs it.&lt;/P&gt;&lt;P&gt;3. Let rules find the problem and the LLM explain it. Deterministic checks (spill above a threshold, low CPU in system.compute.node_timeline, a few stages dominating runtime, autoscaling that never scales down) produce findings with numbers, and the LLM turns them into prioritised recommendations. That keeps the advice grounded and makes it much easier to evaluate.&lt;/P&gt;&lt;P&gt;On the three options:&lt;/P&gt;&lt;P&gt;• Agent Framework: the core. Author it as a ResponsesAgent (LangGraph or plain Python both work), log it with MLflow, deploy to Model Serving, and you get tracing on every tool call.&lt;/P&gt;&lt;P&gt;• Genie Space: good for follow-ups like "cost by cluster type for this job" over the same tables, and it can sit next to the agent as another tool, but it won't do the event log analysis or the recommendations.&lt;/P&gt;&lt;P&gt;• Databricks Apps: the front end, not the architecture. Put the chat UI or a job picker there and call the serving endpoint.&lt;/P&gt;&lt;P&gt;One thing worth deciding early: should the agent only recommend config changes, or also compare before/after once someone applies them? The second needs run history tagged with the config version, which is much easier to add now than later.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2026 05:22:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/best-architecture-for-building-a-custom-agent-in-databricks/m-p/174901#M2246</guid>
      <dc:creator>FrankAzzollini</dc:creator>
      <dc:date>2026-10-29T05:22:11Z</dc:date>
    </item>
  </channel>
</rss>

