fix(actor): Validate required node config keys in compiler._map_node() #10561

Open
opened 2026-04-18 17:16:04 +00:00 by HAL9000 · 0 comments
Owner

Metadata

Commit Message: fix(actor): Validate required node config keys in compiler._map_node()

Branch Name: fix/actor-node-config-validation

Background and Context

The _map_node() function in src/cleveragents/actor/compiler.py maps actor schema nodes to LangGraph NodeConfig objects, but it does not validate that the node.config dictionary contains the required keys for each node type. This can lead to runtime errors when the compiled actor is executed, as missing configuration will result in None values being passed to NodeConfig constructors.

Code Evidence

Lines 130-145 in src/cleveragents/actor/compiler.py:

def _map_node(node: NodeDefinition) -> lg_nodes.NodeConfig:
    """Map an actor schema node to a LangGraph ``NodeConfig``."""
    lg_type = _NODE_TYPE_MAP.get(node.type, lg_nodes.NodeType.FUNCTION)
    config = node.config
    return lg_nodes.NodeConfig(
        name=node.id,
        type=lg_type,
        agent=config.get("agent") if node.type == NodeType.AGENT else None,
        function=(
            config.get("function") if node.type == NodeType.CONDITIONAL else None
        ),
        tools=config.get("tools", []) if node.type == NodeType.TOOL else [],
        subgraph=(config.get("actor_ref") if node.type == NodeType.SUBGRAPH else None),
        metadata=dict(config),
    )

The function uses config.get() with no validation that:

  • AGENT nodes have an "agent" key
  • CONDITIONAL nodes have a "function" key
  • TOOL nodes have a "tools" key
  • SUBGRAPH nodes have an "actor_ref" key

If these keys are missing, the function silently returns None for those fields, which may cause errors downstream.

Environment Verification

This is reproducible by:

  1. Creating an ActorConfigSchema with a GRAPH type
  2. Adding a node with type=AGENT but no "agent" key in config
  3. Calling compile_actor() on the config
  4. The compiled actor will have agent=None, which may cause runtime errors

Expected Behavior

The _map_node() function should validate that all required configuration keys are present for each node type before attempting to map the node. If required keys are missing, a clear and descriptive error should be raised that identifies:

  • The node ID
  • The node type
  • The missing configuration key(s)

This validation should occur during compilation, not during graph execution, allowing developers to catch configuration errors early.

Acceptance Criteria

  • AGENT nodes must have "agent" key in config
  • CONDITIONAL nodes must have "function" key in config
  • TOOL nodes must have "tools" key in config
  • SUBGRAPH nodes must have "actor_ref" key in config
  • Missing keys raise MissingNodeError with descriptive message
  • Error message includes node ID and missing key name

Subtasks

  • Add validation function for node config keys
  • Update _map_node() to call validation before mapping
  • Create test cases for each node type with missing required keys
  • Verify error messages are clear and actionable
  • Run full test suite to ensure no regressions

Definition of Done

This issue is complete when:

  • All required config keys are validated before mapping
  • Missing keys raise appropriate exceptions with clear error messages
  • Test cases cover all node types with missing required keys
  • All existing tests pass
  • Code coverage remains >=97%

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit Message:** fix(actor): Validate required node config keys in compiler._map_node() **Branch Name:** fix/actor-node-config-validation ## Background and Context The `_map_node()` function in `src/cleveragents/actor/compiler.py` maps actor schema nodes to LangGraph `NodeConfig` objects, but it does not validate that the `node.config` dictionary contains the required keys for each node type. This can lead to runtime errors when the compiled actor is executed, as missing configuration will result in `None` values being passed to `NodeConfig` constructors. ### Code Evidence Lines 130-145 in `src/cleveragents/actor/compiler.py`: ```python def _map_node(node: NodeDefinition) -> lg_nodes.NodeConfig: """Map an actor schema node to a LangGraph ``NodeConfig``.""" lg_type = _NODE_TYPE_MAP.get(node.type, lg_nodes.NodeType.FUNCTION) config = node.config return lg_nodes.NodeConfig( name=node.id, type=lg_type, agent=config.get("agent") if node.type == NodeType.AGENT else None, function=( config.get("function") if node.type == NodeType.CONDITIONAL else None ), tools=config.get("tools", []) if node.type == NodeType.TOOL else [], subgraph=(config.get("actor_ref") if node.type == NodeType.SUBGRAPH else None), metadata=dict(config), ) ``` The function uses `config.get()` with no validation that: - AGENT nodes have an "agent" key - CONDITIONAL nodes have a "function" key - TOOL nodes have a "tools" key - SUBGRAPH nodes have an "actor_ref" key If these keys are missing, the function silently returns `None` for those fields, which may cause errors downstream. ### Environment Verification This is reproducible by: 1. Creating an `ActorConfigSchema` with a GRAPH type 2. Adding a node with `type=AGENT` but no "agent" key in config 3. Calling `compile_actor()` on the config 4. The compiled actor will have `agent=None`, which may cause runtime errors ## Expected Behavior The `_map_node()` function should validate that all required configuration keys are present for each node type before attempting to map the node. If required keys are missing, a clear and descriptive error should be raised that identifies: - The node ID - The node type - The missing configuration key(s) This validation should occur during compilation, not during graph execution, allowing developers to catch configuration errors early. ## Acceptance Criteria - [ ] AGENT nodes must have "agent" key in config - [ ] CONDITIONAL nodes must have "function" key in config - [ ] TOOL nodes must have "tools" key in config - [ ] SUBGRAPH nodes must have "actor_ref" key in config - [ ] Missing keys raise `MissingNodeError` with descriptive message - [ ] Error message includes node ID and missing key name ## Subtasks - [ ] Add validation function for node config keys - [ ] Update `_map_node()` to call validation before mapping - [ ] Create test cases for each node type with missing required keys - [ ] Verify error messages are clear and actionable - [ ] Run full test suite to ensure no regressions ## Definition of Done This issue is complete when: - All required config keys are validated before mapping - Missing keys raise appropriate exceptions with clear error messages - Test cases cover all node types with missing required keys - All existing tests pass - Code coverage remains >=97% --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10561
No description provided.