My Project
Loading...
Searching...
No Matches
lg_agent.s_chat_graph Namespace Reference

Functions

tuple[dict, dict] _extract_plan (SPlannerState state)
 _plan_value (SPlannerState state, str key, default=None)
 invoke_db_helper (SPlannerState state)
 invoke_web_helper (SPlannerState state)
 invoke_insertion_helper (SPlannerState state)
 route_from_planning (SPlannerState state)
SPlannerState answer_node (SPlannerState 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"]
 graph_builder = StateGraph(SPlannerState)
 s_planner_node
 defer
 s_chat_graph = graph_builder.compile()

Detailed Description

Copyright 2026 Luca Silver

Student-facing chat agent that routes student queries through planning and helper graphs.

Functions:
- `invoke_db_helper`: Invokes the database helper graph and merges results back to planner state.
- `invoke_web_helper`: Invokes the web search helper graph and merges results back to planner state.
- `invoke_insertion_helper`: Invokes the insertion helper graph for student profile updates.
- `route_from_planning`: Routes the planner's decision to appropriate helper graphs or answer node. Enforces a maximum number of loops before forcing an answer.
- `answer_node`: Appends the final planner response to the conversation message history.

Graph Structure:
- START -> planning
- planning -> [invoke_db_helper | invoke_web_helper | invoke_insertion_helper | answer_node] (conditional) (can be parallel)
- invoke_db_helper -> planning (feedback loop) (deferred)
- invoke_web_helper -> planning (feedback loop) (deferred)
- invoke_insertion_helper -> planning (feedback loop) (deferred)
- answer_node -> END

Exports:
- `s_chat_graph`: Compiled LangGraph student chat agent.

Loop limits are defined in config.json.

Function Documentation

◆ _extract_plan()

tuple[dict, dict] _extract_plan ( SPlannerState state)
protected
Safely extracts planner output and nested content dict from state.

Some model/tooling paths may produce plan payloads where "content" is a
string or missing entirely. This helper normalizes both objects so routing
code can perform key lookups without type errors.

◆ _plan_value()

_plan_value ( SPlannerState state,
str key,
default = None )
protected
Reads a planner field from either top-level plan or nested content.

◆ answer_node()

SPlannerState answer_node ( SPlannerState state)
Appends the final planner answer to the conversation state.

Args:
    state (SPlannerState): Current planner state containing the final answer in
        plan["answer"].

Returns:
    SPlannerState: Updated state with the final AI answer appended to messages.

◆ invoke_db_helper()

invoke_db_helper ( SPlannerState state)
Invokes the student database helper graph and merges its result back into state.

The planner decides which database information is needed. This node forwards that
request to the database helper graph, then appends the returned query/result pair
to the accumulated db_info list.

Args:
    state (SPlannerState): Current planner state containing the selected database
        request in plan["info_needed_db"].

Returns:
    dict: Partial state update with the updated "db_info" list.

◆ invoke_insertion_helper()

invoke_insertion_helper ( SPlannerState state)
Invokes the insertion helper graph and stores the insertion result.

The student planner may determine that new profile or preference information
should be inserted into the database. This node forwards the insertion request
and stores the helper's final status message back into the student planner state.

Args:
    state (SPlannerState): Current planner state containing the insertion text in
        plan["info_to_insert"].

Returns:
    dict: Partial state update with the insertion_result string.

◆ invoke_web_helper()

invoke_web_helper ( SPlannerState state)
Invokes the web helper graph and merges its result back into state.

The planner decides which web information is needed. This node forwards that
request to the web helper graph, then appends the returned query/result pair to
the accumulated web_info list.

Args:
    state (SPlannerState): Current planner state containing the selected web
        request in plan["info_needed_web"].

Returns:
    dict: Partial state update with the updated "web_info" list.

◆ route_from_planning()

route_from_planning ( SPlannerState state)
Chooses which helper graphs to run after planning.

The planner can request database lookups, web lookups, insertion, or an immediate
answer. This router converts the plan into one or more graph sends. When both
database and web information are requested, they are dispatched in parallel.
If no tools are needed, control routes directly to the answer node.

Args:
    state (SPlannerState): Current planner state containing the loop counter and
        the structured plan produced by the planning node.

Returns:
    list[Send]: One or more graph sends describing the next execution branch.

Variable Documentation

◆ CONFIG

lg_agent.s_chat_graph.CONFIG = json.load(f)

◆ CONFIG_PATH

lg_agent.s_chat_graph.CONFIG_PATH = os.path.join(PARENT_DIR, "config.json")

◆ defer

lg_agent.s_chat_graph.defer

◆ graph_builder

lg_agent.s_chat_graph.graph_builder = StateGraph(SPlannerState)

◆ LOOP_CONFIG

lg_agent.s_chat_graph.LOOP_CONFIG = CONFIG["loop_limits"]

◆ PARENT_DIR

lg_agent.s_chat_graph.PARENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

◆ s_chat_graph

lg_agent.s_chat_graph.s_chat_graph = graph_builder.compile()

◆ s_planner_node

lg_agent.s_chat_graph.s_planner_node