My Project
Loading...
Searching...
No Matches
lg_agent.utilities.model_inits Namespace Reference

Functions

tuple[dict, str] _load_model_config ()
str _normalize_model_name (str model_name)
FakeChatModel _s_planner_tool_testing_model ()
FakeChatModel _a_planner_tool_testing_model ()
FakeChatModel _planner_loop_testing_model ()
FakeChatModel _s_db_tool_testing_model ()
FakeChatModel _a_db_tool_testing_model ()
FakeChatModel _db_do_nothing_testing_model ()
FakeChatModel _db_loop_testing_model ()
FakeChatModel _web_tool_testing_model ()
FakeChatModel _web_do_nothing_testing_model ()
FakeChatModel _web_loop_testing_model ()
FakeChatModel _insertion_tool_testing_model ()
FakeChatModel _insertion_do_nothing_testing_model ()
FakeChatModel _insertion_loop_testing_model ()
FakeChatModel _alerts_testing_model ()
 _create_model (str model_name, str node_name)

Variables

 PARENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
 ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
 model_select
 mode
 planning_llm = _create_model(model_select["planning"], "planning")
 db_llm = _create_model(model_select["db"], "db")
 web_llm = _create_model(model_select["web"], "web")
 insertion_llm = _create_model(model_select["insertion"], "insertion")
 alerts_llm = _create_model(model_select["alerts"], "alerts")

Detailed Description

Copyright 2026 Luca Silver

Initializes language models for different agent nodes and modes (production or testing).

Functions:
- `_load_model_config`: Loads model configuration from model_select.json.
- `_normalize_model_name`: Normalizes model names by converting to lowercase and replacing hyphens with underscores.
- `_s_planner_tool_testing_model`: Creates a fake testing model for the student planner node that calls all helper agents.
- `_a_planner_tool_testing_model`: Creates a fake testing model for the advisor planner node that calls all helper agents.
- `_planner_loop_testing_model`: Creates a fake testing model for the planner nodes to test loop limits.
- `_s_db_tool_testing_model`: Creates a fake testing model for the student database helper node that test all its tools.
- `_a_db_tool_testing_model`: Creates a fake testing model for the advisor database helper node that test all its tools.
- `_db_loop_testing_model`: Creates a fake testing model for the database helper nodes to test loop limits.
- `_db_do_nothing_testing_model`: Creates a fake testing model for the database helper nodes that does nothing to help test planner loop limits.
- `_web_tool_testing_model`: Creates a fake testing model for the web helper node that tests all its tools.
- `_web_loop_testing_model`: Creates a fake testing model for the web helper nodes to test loop limits.
- `_web_do_nothing_testing_model`: Creates a fake testing model for the web helper nodes that does nothing.
- `_insertion_tool_testing_model`: Creates a fake testing model for the insertion helper node that tests all its tools.
- `_insertion_loop_testing_model`: Creates a fake testing model for the insertion helper node to test loop limits.
- `_insertion_do_nothing_testing_model`: Creates a fake testing model for the insertion helper node that does nothing.
- `_alerts_testing_model`: Creates a fake testing model for the alerts agent node.
- `_create_model`: Factory function that creates appropriate chat models based on model name and node type.

Modules Initialized:
- `planning_llm`: Language model for planning nodes.
- `db_llm`: Language model for database helper nodes.
- `web_llm`: Language model for web search helper nodes.
- `insertion_llm`: Language model for insertion helper nodes.
- `alerts_llm`: Language model for alerts agent nodes.

Function Documentation

◆ _a_db_tool_testing_model()

FakeChatModel _a_db_tool_testing_model ( )
protected
Create a fake advisor-database helper model that exercises DB tools.

Similar to `_s_db_tool_testing_model` but with advisor-oriented IDs
and scenarios (e.g., retrieving advisor students). Produces tool
calls that exercise edge cases and error paths to validate the
advisor DB helper implementation.

Returns:
    FakeChatModel: a test model instance for advisor DB tools.

Note: This should be used with ``TestDB.db`` configured as the database and with Bill Bebop as the user.

◆ _a_planner_tool_testing_model()

FakeChatModel _a_planner_tool_testing_model ( )
protected
Create a fake chat model for advisor planning tool tests.

Similar to `_s_planner_tool_testing_model` but tailored for the
advisor/planner flow. Produces messages that request database and
web helper tool usage, followed by completion and fallback
responses for testing.

Returns:
    FakeChatModel: a test model instance for advisor planning.

Note: This should be used with advisor accounts only.

◆ _alerts_testing_model()

FakeChatModel _alerts_testing_model ( )
protected
Create a simple alerts agent test model.

Produces messages with serialized JSON containing `relivent_events`
(sic) lists to simulate alerts being detected or none found. Used in
tests for alerts processing logic.

Returns:
    FakeChatModel: a test model for the alerts agent.

◆ _create_model()

_create_model ( str model_name,
str node_name )
protected
Factory to create a chat model instance for a given node.

Args:
    model_name (str): The model name from configuration (e.g. "sonnet-4-6",
        "gpt_4o", or one of the special testing identifiers like
        "s_tool_test", "a_tool_test", "loop_test", "do_nothing_test").
    node_name (str): The node type requesting the model ("planning",
        "db", "web", "insertion", "alerts").

Returns:
    An instance of a chat model (langchain Chat model or
    `FakeChatModel`) appropriate for the request.

Raises:
    ValueError: if required environment API keys are missing or if an
        invalid model or node name is provided.

◆ _db_do_nothing_testing_model()

FakeChatModel _db_do_nothing_testing_model ( )
protected
Create a DB helper test model that intentionally does nothing.

This model returns simple messages with no `ToolCall`s. It's useful
for verifying planner loop behavior when helpers do not request
further actions (helps detect broken loop termination logic).

Returns:
    FakeChatModel: a test model that produces no tool calls.

◆ _db_loop_testing_model()

FakeChatModel _db_loop_testing_model ( )
protected
Create a DB helper model that issues tool calls across multiple loops.

Produces a sequence of messages, each containing a `get_current_time`
`ToolCall`. Used to validate loop limits are working properly.

Returns:
    FakeChatModel: a loop-testing DB helper model.

Notes: This should be used with db loop limit set to 3 for whichever version of the db agent you are testing.

◆ _insertion_do_nothing_testing_model()

FakeChatModel _insertion_do_nothing_testing_model ( )
protected
Create an insertion helper model that performs no insertions.

Used to test planner loop termination and fallback when insertion
helpers do not request further work.

Returns:
    FakeChatModel: a do-nothing insertion helper model.

◆ _insertion_loop_testing_model()

FakeChatModel _insertion_loop_testing_model ( )
protected
Create an insertion helper model that issues repeated tool calls.

Produces several messages that each request `get_student_interests`.
Helps validate loop counting and termination behavior for insertion
helpers.

Returns:
    FakeChatModel: a loop-testing insertion helper model.

Note: This should be used with the insertion loop limit set to 3.

◆ _insertion_tool_testing_model()

FakeChatModel _insertion_tool_testing_model ( )
protected
Create a fake insertion-helper model that exercises insertion tools.

The model generates `ToolCall`s for reading and writing student
interests and tracked sections, including invalid inputs to test
validation and error handling.

Returns:
    FakeChatModel: a test model for insertion helper tooling.

◆ _load_model_config()

tuple[dict, str] _load_model_config ( )
protected
Load and return model selection configuration.

Reads `config.json` from the repository root and extracts the
`model_select` section. Returns a tuple `(models, mode)` where
`models` is the dictionary of model choices for the active mode
and `mode` is the active mode string (e.g. "production", "testing").

Returns:
    tuple[dict, str]: (models, mode)
Raises:
    FileNotFoundError: if `config.json` does not exist.
    KeyError: if expected keys are missing from the config.

◆ _normalize_model_name()

str _normalize_model_name ( str model_name)
protected
Normalize a model name string for internal matching.

Performs a simple normalization by trimming whitespace, converting
to lowercase, and replacing hyphens with underscores. This ensures
configuration names like "sonnet-4-6" match internal case labels
such as "sonnet_4_6".

Args:
    model_name (str): The model name from configuration.

Returns:
    str: The normalized model name.

◆ _planner_loop_testing_model()

FakeChatModel _planner_loop_testing_model ( )
protected
Create a fake planner model that repeatedly requests database help.

This test model produces multiple messages that continue to request
database information across several loops. It is intended to
validate planner loop limits and ensure the controller stops after
a configured number of iterations.

Returns:
    FakeChatModel: a loop-testing model instance.

Note: This should be used with the planner loop limit set to 3 for whichever version of the planner is being tested.

◆ _s_db_tool_testing_model()

FakeChatModel _s_db_tool_testing_model ( )
protected
Create a fake student-database helper model that exercises DB tools.

The returned `FakeChatModel` contains an initial message
that includes a long list of `ToolCall` entries exercising the
database helper API (queries, filters, edge cases). Follow-up
messages indicate completion and fallback behavior. Use this model
in tests to validate the DB helper tooling and error handling.

Returns:
    FakeChatModel: a test model instance for student DB tools.

Note: This should be used with ``TestDB.db`` configured as the database and with John Doe as the user.

◆ _s_planner_tool_testing_model()

FakeChatModel _s_planner_tool_testing_model ( )
protected
Create a fake chat model for student planning tool tests.

The returned `FakeChatModel` yields a sequence of
`AIMessage`s that instruct the planner to exercise database,
web, and insertion helper tools, followed by completion/fallback
messages. This is used in unit/integration tests to simulate a
planning model that requests helper tool calls.

Returns:
    FakeChatModel: a test model instance that produces messages
        and tool call instructions.

Note: This should be used with student accounts only.

◆ _web_do_nothing_testing_model()

FakeChatModel _web_do_nothing_testing_model ( )
protected
Create a web helper test model that returns no actionable tool calls.

Useful for testing planner loop termination and fallback behavior
when the helper does not request further actions.

Returns:
    FakeChatModel: a do-nothing web helper model.

◆ _web_loop_testing_model()

FakeChatModel _web_loop_testing_model ( )
protected
Create a web helper model that issues web tool calls across loops.

Produces several messages each requesting a `web_search`. Intended
to validate loop limits and correct handling of repeated helper
requests.

Returns:
    FakeChatModel: a loop-testing web helper model.

Note: This should be used with the web loop limit set to 3.

◆ _web_tool_testing_model()

FakeChatModel _web_tool_testing_model ( )
protected
Create a fake student-web helper model that exercises web tools.

The model produces `web_search` and `get_web_page_content` tool calls
covering normal and edge-case inputs (empty queries, invalid URLs,
large inputs). Use this to validate web helper behavior and error
handling in tests.

Returns:
    FakeChatModel: a test model instance for student web helper.

Variable Documentation

◆ alerts_llm

lg_agent.utilities.model_inits.alerts_llm = _create_model(model_select["alerts"], "alerts")

◆ db_llm

lg_agent.utilities.model_inits.db_llm = _create_model(model_select["db"], "db")

◆ insertion_llm

lg_agent.utilities.model_inits.insertion_llm = _create_model(model_select["insertion"], "insertion")

◆ mode

lg_agent.utilities.model_inits.mode

◆ model_select

lg_agent.utilities.model_inits.model_select

◆ PARENT_DIR

lg_agent.utilities.model_inits.PARENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

◆ planning_llm

lg_agent.utilities.model_inits.planning_llm = _create_model(model_select["planning"], "planning")

◆ ROOT_DIR

lg_agent.utilities.model_inits.ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))

◆ web_llm

lg_agent.utilities.model_inits.web_llm = _create_model(model_select["web"], "web")