dbx-unifiedchat

Multi-Agent Source Code

This directory contains all agent logic in a modular structure.

๐ŸŽฏ Purpose

This is the single source of truth for agent code, used by:

All three workflows use the same code from this directory!

๐Ÿ“‚ Directory Structure

src/multi_agent/
โ”œโ”€โ”€ __init__.py          # Package exports
โ”œโ”€โ”€ main.py              # CLI entry point (local dev)
โ”œโ”€โ”€ agents/              # Agent implementations
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ clarification.py              # Clarification node + helpers
โ”‚   โ”œโ”€โ”€ planning.py                   # Planning node + helpers
โ”‚   โ”œโ”€โ”€ planning_agent.py             # PlanningAgent class
โ”‚   โ”œโ”€โ”€ sql_synthesis.py              # SQL synthesis nodes
โ”‚   โ”œโ”€โ”€ sql_synthesis_agents.py       # SQL synthesis agent classes
โ”‚   โ”œโ”€โ”€ sql_execution.py              # SQL execution node
โ”‚   โ”œโ”€โ”€ sql_execution_agent.py        # SQLExecutionAgent class
โ”‚   โ”œโ”€โ”€ summarize.py                  # Summarization node
โ”‚   โ””โ”€โ”€ summarize_agent.py            # ResultSummarizeAgent class
โ”œโ”€โ”€ core/                # Core infrastructure
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ config.py                     # Configuration management
โ”‚   โ”œโ”€โ”€ state.py                      # State TypedDicts and helpers
โ”‚   โ””โ”€โ”€ graph.py                      # LangGraph workflow
โ”œโ”€โ”€ tools/               # Agent tools
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ uc_functions.py               # Unity Catalog functions
โ””โ”€โ”€ utils/               # Utilities
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ conversation.py               # Conversation management
    โ””โ”€โ”€ intent_detection_service.py   # Intent detection

๐Ÿ› ๏ธ For Developers

Adding a New Agent

  1. Create agent file in agents/: agents/my_new_agent.py
"""My new agent implementation."""
from typing import Dict, Any
from ..core.state import AgentState

def my_new_agent_node(state: AgentState) -> Dict[str, Any]:
    """
    My new agent node function.
    
    Args:
        state: Current agent state
        
    Returns:
        State updates
    """
    # Your agent logic here
    return {
        "messages": [{"role": "assistant", "content": "response"}],
        "next_agent": "summarize"
    }
  1. Register in graph (core/graph.py):
from ..agents.my_new_agent import my_new_agent_node

# In create_super_agent_hybrid():
workflow.add_node("my_new_agent", my_new_agent_node)
workflow.add_edge("some_node", "my_new_agent")
  1. Add tests (tests/unit/test_my_new_agent.py):
import pytest
from src.multi_agent.agents.my_new_agent import my_new_agent_node

def test_my_new_agent():
    state = {"messages": []}
    result = my_new_agent_node(state)
    assert "messages" in result
  1. Test locally:
    pytest tests/unit/test_my_new_agent.py -v
    python -m src.multi_agent.main --query "test new agent"
    

Modifying Existing Agent

  1. Edit the agent file (e.g., agents/supervisor.py)
  2. Run agent-specific tests: pytest tests/unit/test_supervisor.py -v
  3. Run full test suite: pytest tests/
  4. Test locally: python -m src.multi_agent.main --query "test"
  5. Test in Databricks: notebooks/test_agent_databricks.py
  6. Deploy: notebooks/deploy_agent.py

Working with Agent Classes vs Node Functions

The codebase has two patterns:

Agent Classes (e.g., PlanningAgent):

Agent Node Functions (e.g., planning_node):

Pattern:

# Agent class
class PlanningAgent:
    def __init__(self, llm, vector_search_index):
        self.llm = llm
        self.vector_search_index = vector_search_index
    
    def plan(self, query):
        # Complex planning logic
        pass

# Node function (used by graph)
def planning_node(state: AgentState) -> dict:
    # Extract context
    query = state["current_turn"]["query"]
    
    # Get or create agent instance
    agent = get_cached_planning_agent()
    
    # Call agent
    result = agent.plan(query)
    
    # Return state updates
    return {"plan": result}

Code Style

Follow these guidelines:

# Format code
black src/multi_agent/
isort src/multi_agent/

# Lint
flake8 src/multi_agent/

# Type check
mypy src/multi_agent/

Standards:

๐Ÿ”„ Three Workflows Using This Code

Workflow 1: Local Development

# Uses config.py + .env
python -m src.multi_agent.main --query "test"

Configuration: .env file Purpose: Fast iteration, unit testing

Workflow 2: Databricks Testing

# Uses dev_config.yaml
# In notebooks/test_agent_databricks.py
import sys
sys.path.insert(0, "../src")
from multi_agent.core.graph import create_agent_graph

Configuration: dev_config.yaml Purpose: Test with real Databricks services

Workflow 3: Production Deployment

# Uses prod_config.yaml
# In notebooks/deploy_agent.py
mlflow.pyfunc.log_model(
    python_model="./agent.py",
    code_paths=["../src/multi_agent"],  # Packages this code!
    model_config="../prod_config.yaml"
)

Configuration: prod_config.yaml Purpose: Production deployment to Model Serving

๐Ÿ“– Key Files

File Purpose When to Edit
agents/*.py Agent implementations Adding/modifying agents
core/state.py State definitions Changing state schema
core/graph.py Workflow graph Changing agent flow
core/config.py Configuration Adding config values
tools/*.py Agent tools Adding new tools
utils/*.py Utilities Adding helpers
main.py CLI entry point Changing CLI behavior

๐Ÿงช Testing

# Test imports work
python -c "from src.multi_agent import *; print('โœ“ Imports OK')"

# Run unit tests
pytest tests/unit/ -v

# Test specific agent
pytest tests/unit/test_planning.py -v

# Test locally
python -m src.multi_agent.main --query "test" --verbose

๐Ÿ“š Documentation

๐Ÿค Contributing

When contributing:

  1. Follow the structure: Keep code organized by type (agents, core, tools, utils)
  2. Keep files small: Target <500 lines per file
  3. Add tests: Every new feature needs tests
  4. Update docs: Update relevant README files
  5. Test all three workflows: Ensure code works locally, in Databricks, and deploys correctly

See ../../CONTRIBUTING.md for complete guidelines.


This is the heart of the system! All agent logic lives here. ๐Ÿ’ก