|
My Project
|
Functions | |
| DatabaseHelperOutput | format_db_output (DatabaseHelperState state) |
| tool_route (DatabaseHelperState state) | |
Variables | |
| PARENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | |
| CONFIG_PATH = os.path.join(PARENT_DIR, "config.json") | |
| CONFIG = json.load(f) | |
| LOOP_CONFIG = CONFIG["loop_limits"] | |
| tool_node = ToolNode(db_tools) | |
| alt_tool_node = ToolNode(alt_db_tools) | |
| graph_builder = StateGraph(DatabaseHelperState, output_schema=DatabaseHelperOutput) | |
| db_graph = graph_builder.compile() | |
Copyright 2026 Luca Silver Database helper subgraph that executes database queries for the planning agents. Functions: - `format_db_output`: Normalizes database helper response into standardized helper output schema. - `tool_route`: Conditionally routes database helper loop based on tool calls and loop count. Graph Structure: - START -> db_node - db_node -> [tool_node | alt_tool_node | format_db_output] (conditional routing based on tool_route) - tool_node -> db_node (feedback loop) - alt_tool_node -> db_node (feedback loop) - format_db_output -> END Exports: - `db_graph`: Compiled LangGraph database helper subgraph. Supports both standard (student) and alternate (advisor) tool sets. Loop limits are defined in config.json.
| DatabaseHelperOutput format_db_output | ( | DatabaseHelperState | state | ) |
Normalizes the database helper response into the helper output schema.
If the last message is a tool message (meaning the database helper passed its
loop limit without providing a final answer), the full message history is serialized
into a single string so the planner can inspect the tool trail. Otherwise, the
final AI message content is returned directly as the query result.
Args:
state (DatabaseHelperState): Helper state containing the request context and
the message history produced by the database helper loop.
Returns:
DatabaseHelperOutput: Output object containing the original query and the
formatted database result string.
| tool_route | ( | DatabaseHelperState | state | ) |
Routes the database helper loop based on tool usage and loop count.
The database helper is allowed a limited number of iterations. If the latest AI
message includes tool calls, the graph routes to the appropriate tool node.
Otherwise it formats the output. If the loop limit is reached, the function
enforces a final response path and includes a fallback message when necessary.
Args:
state (DatabaseHelperState): Current helper state including messages,
account type, loop counter, and requested information.
Returns:
str: The next node name to execute.
| lg_agent.db_helper_graph.alt_tool_node = ToolNode(alt_db_tools) |
| lg_agent.db_helper_graph.CONFIG = json.load(f) |
| lg_agent.db_helper_graph.CONFIG_PATH = os.path.join(PARENT_DIR, "config.json") |
| lg_agent.db_helper_graph.db_graph = graph_builder.compile() |
| lg_agent.db_helper_graph.graph_builder = StateGraph(DatabaseHelperState, output_schema=DatabaseHelperOutput) |
| lg_agent.db_helper_graph.LOOP_CONFIG = CONFIG["loop_limits"] |
| lg_agent.db_helper_graph.PARENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
| lg_agent.db_helper_graph.tool_node = ToolNode(db_tools) |