Skip to content

Refactor: Establish Shared Core Architecture for Agentic RAG#201

Open
RajSidwadkar wants to merge 3 commits intokubeflow:mainfrom
RajSidwadkar:refactor-shared-core
Open

Refactor: Establish Shared Core Architecture for Agentic RAG#201
RajSidwadkar wants to merge 3 commits intokubeflow:mainfrom
RajSidwadkar:refactor-shared-core

Conversation

@RajSidwadkar
Copy link
Copy Markdown

Architectural Context & Motivation

This pull request addresses the structural limitations identified in Issue #200. As the application transitions from linear, non-deterministic tool-calling chains toward a robust Directed Acyclic Graph (DAG) for semantic routing, the existing codebase presented a risk of tight coupling.

Previously, agent logic was deeply integrated into the specific network transport layers (server/app.py for WebSockets and server-https/app.py for REST). Placing complex state-machine logic in these directories would violate DRY principles, introduce synchronization risks between the two APIs, and prevent isolated unit testing.

Implementation Details

This PR introduces the core_agent/ module, establishing a single source of truth for all conversational intelligence and retrieval routing.

  • Transport Decoupling: Both the ASGI WebSocket endpoints and the FastAPI HTTP endpoints have been refactored to act purely as network interfaces. They now import and invoke the compiled LangGraph state machine from core_agent.graph.

  • State Management (core_agent/graph.py): Scaffolded the foundational TypedDict state schema, integrating intent classification nodes and conditional edge definitions for deterministic routing.

  • Retrieval Isolation (core_agent/tools.py): Abstracted the Milvus partition targeting logic into independent callable tools, paving the way for the specialized index architecture (Docs, GitHub Issues, Platform Architecture).

Testing & Validation

To ensure high stability and rapid CI/CD execution, the routing logic has been entirely decoupled from external network latency.

  • Introduced tests/test_graph.py utilizing standard pytest and unittest.mock.

  • Transition Assertions: Verified all conditional edges (e.g., ensuring Debugging intents strictly route to the github_issues node).

  • Cyclic Recovery: Validated the failure-recovery loop by simulating hallucinated LLM responses, asserting that the state's error_count increments correctly and triggers a retry rather than failing silently or causing an infinite loop.

Note to Maintainers: This structural refactor serves as the foundational Phase 1 architecture for my GSoC proposal. It is designed to cleanly integrate alongside the ContextWindowManager optimizations introduced in PR #129.

Resolves: #200

Signed-off-by: Raj <rajsidwadkar777@gmail.com>
…mory manager

Signed-off-by: Raj <rajsidwadkar777@gmail.com>
Resolves kubeflow#200. This commit introduces the foundational Shared Core architecture for deterministic agent routing.
- Creates core_agent/graph.py to act as the single source of truth for the LangGraph state machine.
- Decouples AI routing logic from the FastAPI and WebSocket transport layers.
- Adds comprehensive, fully-mocked PyTest suite in tests/test_graph.py to validate cyclic error correction and conditional edge transitions without network overhead.

Signed-off-by: Raj <rajsidwadkar777@gmail.com>
@google-oss-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign franciscojavierarceo for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant