Skip to content

Development#44

Merged
ChrisCoder9000 merged 5 commits intomainfrom
development
Mar 29, 2026
Merged

Development#44
ChrisCoder9000 merged 5 commits intomainfrom
development

Conversation

@ChrisCoder9000
Copy link
Copy Markdown
Contributor

@ChrisCoder9000 ChrisCoder9000 commented Mar 29, 2026

Summary by CodeRabbit

  • New Features

    • Added video tutorial link to documentation.
  • Improvements

    • Enhanced entity status validation with robust error handling for missing graph data.
    • Optimized embedding model loading for improved startup performance.
    • Strengthened brain ID validation during creation.
    • Improved graph neighbor vector filtering and metadata validation.
    • Converted MCP tools to async for better concurrency.
  • Bug Fixes

    • Fixed mutable default argument handling across multiple endpoints.
    • Removed debug console output.

cursoragent and others added 4 commits March 23, 2026 08:12
Co-authored-by: Christian <ChrisCoder9000@users.noreply.github.com>
Co-authored-by: Christian <ChrisCoder9000@users.noreply.github.com>
…rovements-62aa

Refactor graph neighbor reduction and harden mutable defaults
- fixed base agent infinite final loop
- added new brain's api format check alphanum + starting with a character
- video on readme
- updated dockerfile with transformer cache folder
- fixed imports of instances
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9148fe1-553a-448b-afc1-32cd95f2a8cb

📥 Commits

Reviewing files that changed from the base of the PR and between 1e32fcc and b017fd5.

⛔ Files ignored due to path filters (1)
  • .github/assets/screen-video.png is excluded by !**/*.png
📒 Files selected for processing (24)
  • Dockerfile
  • README.md
  • pyproject.toml
  • src/adapters/graph.py
  • src/config.py
  • src/constants/prompts/architect_agent.py
  • src/core/agents/architect_agent.py
  • src/core/agents/core/agent_base.py
  • src/core/agents/core/invoke_loop.py
  • src/core/agents/core/prompts.py
  • src/core/agents/tools/architect_agent/ArchitectAgentCreateRelationshipTool.py
  • src/core/agents/tools/janitor_agent/JanitorAgentSearchRelationshipTool.py
  • src/core/layers/graph_consolidation/graph_consolidation.py
  • src/lib/embeddings/client_small.py
  • src/lib/embeddings/local.py
  • src/services/api/controllers/entities.py
  • src/services/api/controllers/system.py
  • src/services/api/routes/retrieve.py
  • src/services/mcp/main.py
  • src/services/mcp/utils.py
  • src/services/observations/main.py
  • src/utils/cleanup.py
  • tests/test_architecture_refactors.py
  • tests/test_static_hardening_refactors.py

📝 Walkthrough

Walkthrough

This PR bumps the version from 2.10.2-dev to 2.10.3-dev while introducing a strategy pattern for neighbor vector reduction, enhancing multi-tool invocation support in the agent loop, refactoring embeddings and MCP service initialization, and fixing mutable default argument issues across multiple modules.

Changes

Cohort / File(s) Summary
Version & Configuration Updates
Dockerfile, README.md, pyproject.toml
Incremented project version from 2.10.2-dev to 2.10.3-dev; removed TRANSFORMERS_CACHE environment variable from Dockerfile; added video thumbnail link to README.
Graph Adapter Refactoring
src/adapters/graph.py
Introduced pluggable NeighborVectorReductionStrategy ABC with SimilarityOnlyReductionStrategy and DescriptionAwareReductionStrategy implementations; added strategy factory and averaging helper; hardened _reduce_neighbor_vectors with explicit metadata/embedding validation and dimensionality checks; updated update_properties to accept optional parameters.
Agent Base & Tool Binding
src/core/agents/core/agent_base.py
Added _base_model field to retain original model instance; introduced conditional tool binding in __init__ with fallback error handling; added _unbind_tools() method for tool restoration; updated model-requirement inspection to use base model.
Invoke Loop Enhancement
src/core/agents/core/invoke_loop.py
Added _infer_tool_from_parsed helper for tool recovery and _log_token_usage for logging token counts; implemented multi-tool support for raw_tc mode; enhanced exception handling with tool unbinding/retry logic; added early termination for token-length limits; improved parsed JSON handling and tool-call resolution.
Prompts & Tool Configuration
src/core/agents/core/prompts.py, src/constants/prompts/architect_agent.py
Updated format_tool_description to accept include_schema parameter; extended build_system_internal_prompt with tools_bound parameter to conditionally include schemas and adjust prompt text; corrected architect agent example JSON payload structure and formatting.
Agent Implementation
src/core/agents/architect_agent.py, src/core/agents/tools/architect_agent/ArchitectAgentCreateRelationshipTool.py
Updated prompt registry lookups with explicit fallback values; clarified UUID format requirements in tool schema descriptions for subject/object fields.
Janitor Tool Refinement
src/core/agents/tools/janitor_agent/JanitorAgentSearchRelationshipTool.py
Replaced list comprehension with explicit loop to conditionally handle tuple vs. single-object serialization shapes in relationship results.
Embeddings Lazy Loading
src/lib/embeddings/client_small.py, src/lib/embeddings/local.py
Deferred SentenceTransformer model initialization from import-time to first use via _get_model() helper; removed instance-level __init__ methods and instance attributes.
Mutable Defaults Fixes
src/services/api/controllers/entities.py, src/services/api/routes/retrieve.py, src/utils/cleanup.py
Replaced mutable list defaults with None in get_entity_status, strip_properties; added safe node resolution in entity-status controller when graph nodes are missing.
System & Brain Validation
src/services/api/controllers/system.py
Added brain_id validation to reject non-alphanumeric IDs and IDs not starting with a letter before delegating to data adapter.
Service Integration & Configuration
src/config.py, src/services/observations/main.py, src/services/mcp/main.py, src/services/mcp/utils.py, src/core/layers/graph_consolidation/graph_consolidation.py
Replaced console print with debug logging in GCPConfig; refactored MCP tools to async with thread-based execution for blocking operations; updated import sources to use shared llm_small_adapter; removed debug output from guard_brainpat.
Test Coverage
tests/test_architecture_refactors.py, tests/test_static_hardening_refactors.py
Added unit tests validating vector reduction validation and averaging logic; added static AST-based tests for parameter defaults, strategy classes, and control-flow hardening patterns.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphAdapter
    participant ReductionStrategy as NeighborVectorReductionStrategy
    participant VectorStore

    Client->>GraphAdapter: _reduce_neighbor_vectors(vectors, description, threshold)
    alt No vectors or missing inputs
        GraphAdapter-->>Client: return empty set
    else Vectors available
        GraphAdapter->>ReductionStrategy: prefilter(vectors, avg_vector, description)
        alt Description present
            ReductionStrategy->>ReductionStrategy: apply reduce_list
        else No description
            ReductionStrategy-->>ReductionStrategy: return vectors as-is
        end
        ReductionStrategy-->>GraphAdapter: filtered_vectors
        
        loop For each vector
            GraphAdapter->>GraphAdapter: validate metadata.uuid
            GraphAdapter->>GraphAdapter: validate embeddings exist & type
            GraphAdapter->>GraphAdapter: validate embedding dimensionality
            alt Valid vector
                GraphAdapter->>GraphAdapter: compute cosine_similarity
                alt Similarity >= threshold
                    GraphAdapter->>GraphAdapter: collect UUID
                end
            else Invalid vector
                GraphAdapter->>GraphAdapter: skip vector
            end
        end
        GraphAdapter-->>Client: set of valid UUIDs
    end
Loading
sequenceDiagram
    participant InvokeLoop
    participant Agent
    participant LLM
    participant ToolExecutor

    InvokeLoop->>Agent: model.invoke(messages)
    alt raw_tc mode & multiple tool_calls
        LLM-->>Agent: response with multiple tool_calls
        Agent-->>InvokeLoop: assistant_message
        InvokeLoop->>InvokeLoop: _log_token_usage(response)
        
        loop For each tool_call
            InvokeLoop->>InvokeLoop: _infer_tool_from_parsed
            InvokeLoop->>ToolExecutor: resolve tool by name
            InvokeLoop->>ToolExecutor: _call_tool(tool, input)
            ToolExecutor-->>InvokeLoop: tool_result
            InvokeLoop->>Agent: append tool_result message
            InvokeLoop->>InvokeLoop: update state/counters
        end
    else Single tool or no raw_tc
        LLM-->>Agent: response
        InvokeLoop->>InvokeLoop: _log_token_usage(response)
        InvokeLoop->>ToolExecutor: execute single tool
        ToolExecutor-->>InvokeLoop: result
        InvokeLoop->>Agent: append tool message
    end
    
    alt Finish reason indicates token limit
        InvokeLoop-->>Client: early termination
    else Continue
        InvokeLoop->>InvokeLoop: process next step
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Possibly related PRs

  • Development #40: Both PRs modify neighbor-vector reduction in src/adapters/graph.py; this PR introduces a strategy pattern with stricter validation while the related PR adds a centralized reduction helper.
  • fix(agent base): fixed many iterations and tool calls #27: Both PRs modify the agent invocation stack across src/core/agents/core/agent_base.py, invoke loop, and prompting utilities; direct overlap in tool binding and invoke logic refactoring.
  • Development #23: Both PRs modify core agent and configuration modules (src/core/agents/architect_agent.py, src/config.py) with overlapping prompt and initialization changes.

Poem

🐰 A strategies bloom where vectors once tangled,
Tools multiply forth, no longer entangled,
Models now wait, then lazily rise,
Embeddings cache, a prudent disguise,
Version's bumped safe—defaults tamed of mutable vice!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch development

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (4.0.5)
src/config.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.config",
"obj": "",
"line": 70,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/config.py",
"symbol": "line-too-long",
"message": "Line too long (121/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.config",
"obj": "",
"line": 217,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/config.py",
"symbol": "line-too-long",
"message": "Line too long (124/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.config",
"obj": "",
"line": 253,
"column": 0,
"endLine": null,

... [truncated 2286 characters] ...

None.",
"message-id": "W1508"
},
{
"type": "refactor",
"module": "src.config",
"obj": "Config",
"line": 274,
"column": 0,
"endLine": 274,
"endColumn": 12,
"path": "src/config.py",
"symbol": "too-many-instance-attributes",
"message": "Too many instance attributes (20/7)",
"message-id": "R0902"
},
{
"type": "convention",
"module": "src.config",
"obj": "",
"line": 17,
"column": 0,
"endLine": 17,
"endColumn": 24,
"path": "src/config.py",
"symbol": "wrong-import-order",
"message": "standard import "pathlib.Path" should be placed before third party import "dotenv"",
"message-id": "C0411"
}
]

src/core/agents/core/invoke_loop.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.core.agents.core.invoke_loop",
"obj": "",
"line": 243,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "line-too-long",
"message": "Line too long (102/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.core.agents.core.invoke_loop",
"obj": "",
"line": 259,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "line-too-long",
"message": "Line too long (147/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.core.agent

... [truncated 14272 characters] ...

W0212"
},
{
"type": "refactor",
"module": "src.core.agents.core.invoke_loop",
"obj": "run_invoke_loop",
"line": 62,
"column": 0,
"endLine": 62,
"endColumn": 19,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "too-many-branches",
"message": "Too many branches (108/12)",
"message-id": "R0912"
},
{
"type": "refactor",
"module": "src.core.agents.core.invoke_loop",
"obj": "run_invoke_loop",
"line": 62,
"column": 0,
"endLine": 62,
"endColumn": 19,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "too-many-statements",
"message": "Too many statements (341/50)",
"message-id": "R0915"
}
]

src/core/agents/core/agent_base.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.core.agents.core.agent_base",
"obj": "",
"line": 1,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/agent_base.py",
"symbol": "missing-module-docstring",
"message": "Missing module docstring",
"message-id": "C0114"
},
{
"type": "error",
"module": "src.core.agents.core.agent_base",
"obj": "",
"line": 4,
"column": 0,
"endLine": 4,
"endColumn": 16,
"path": "src/core/agents/core/agent_base.py",
"symbol": "import-error",
"message": "Unable to import 'langsmith'",
"message-id": "E0401"
},
{
"type": "error",
"module": "src.core.agents.core.

... [truncated 3920 characters] ...

},
{
    "type": "refactor",
    "module": "src.core.agents.core.agent_base",
    "obj": "AgentBase",
    "line": 21,
    "column": 0,
    "endLine": 21,
    "endColumn": 15,
    "path": "src/core/agents/core/agent_base.py",
    "symbol": "too-few-public-methods",
    "message": "Too few public methods (1/2)",
    "message-id": "R0903"
},
{
    "type": "warning",
    "module": "src.core.agents.core.agent_base",
    "obj": "",
    "line": 10,
    "column": 0,
    "endLine": 10,
    "endColumn": 51,
    "path": "src/core/agents/core/agent_base.py",
    "symbol": "unused-import",
    "message": "Unused parse_structured_from_messages imported from parsing",
    "message-id": "W0611"
}

]

  • 15 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChrisCoder9000 ChrisCoder9000 merged commit 5ca139b into main Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants