Skip to content

deps: remove langchain dependency#1869

Merged
goneri merged 1 commit intomainfrom
goneri/deps-remove-langchain-dependency_7621
Feb 12, 2026
Merged

deps: remove langchain dependency#1869
goneri merged 1 commit intomainfrom
goneri/deps-remove-langchain-dependency_7621

Conversation

@goneri
Copy link
Contributor

@goneri goneri commented Feb 12, 2026

Remove langchain and associated dependencies to simplify the codebase
and reduce exposure to third-party dependency issues.

Removed dependencies:

  • langchain~=0.3.10
  • langchain-core~=0.3.81
  • langchain-ollama~=0.3.5
  • langchain-text-splitters~=0.3.11

Removed files:

  • ansible_ai_connect/ai/api/model_pipelines/langchain/ (entire directory)
    • configuration.py
    • pipelines.py
    • tests/test_pipeline.py

Refactored ollama module to be fully self-contained:

Configuration (ollama/configuration.py):

  • Created OllamaConfiguration extending BaseConfig directly
  • Created OllamaBasePipelineConfiguration
  • Removed dependency on langchain configuration classes

Pipelines (ollama/pipelines.py):

  • Created custom OllamaClient for direct Ollama API communication
  • Moved all utility functions from langchain module:
    • message_to_string()
    • create_role_outline()
    • unwrap_role_answer()
    • unwrap_message_with_yaml_answer()
    • unwrap_playbook_answer()
    • unwrap_task_answer()
  • Implemented all pipeline classes without langchain:
    • OllamaMetaData
    • OllamaCompletionsPipeline
    • OllamaPlaybookGenerationPipeline
    • OllamaRoleGenerationPipeline
    • OllamaRoleExplanationPipeline
    • OllamaPlaybookExplanationPipeline

Updated configuration:

  • pyproject.toml: Removed langchain dependencies and pyright path
  • requirements.txt: Regenerated without langchain (15 fewer packages)
  • uv.lock: Regenerated without langchain dependencies
  • .github/workflows/pyright.yml: Removed langchain from CI dependencies

All functionality preserved. Type checking passes with pyright.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com


Note

Medium Risk
Changes core Ollama inference codepaths and parsing behavior (now direct HTTP + custom prompt formatting), so runtime regressions are possible despite test coverage and dependency reduction.

Overview
Removes the langchain-based model pipeline implementation and drops the langchain* dependency chain from the project (CI install, pyproject.toml, requirements.txt, uv.lock, and pyright config).

Refactors the ollama model pipeline to no longer depend on langchain by introducing a small requests-based OllamaClient, re-implementing prompt formatting and response-unwrapping helpers locally, and updating tests to mock HTTP calls instead of langchain_ollama objects. OllamaRoleExplanationPipeline is now an explicit FeatureNotAvailable stub rather than inheriting from the nop pipeline.

Written by Cursor Bugbot for commit 83f5238. This will update automatically on new commits. Configure here.

@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch 3 times, most recently from a06da7b to 30a6f7c Compare February 12, 2026 14:39
acosferreira
acosferreira previously approved these changes Feb 12, 2026
Copy link
Contributor

@acosferreira acosferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch 2 times, most recently from 08082f1 to 04cfe8e Compare February 12, 2026 15:09
@goneri goneri requested a review from acosferreira February 12, 2026 15:10
@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch from 04cfe8e to 388026e Compare February 12, 2026 15:34
@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch from 388026e to 00153f8 Compare February 12, 2026 17:06
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch from 00153f8 to fb5f15c Compare February 12, 2026 19:05
@ansible ansible deleted a comment from sonarqubecloud bot Feb 12, 2026
@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch from fb5f15c to bec1719 Compare February 12, 2026 19:24
Remove langchain and associated dependencies to simplify the codebase
and reduce exposure to third-party dependency issues.

Removed dependencies:
- langchain~=0.3.10
- langchain-core~=0.3.81
- langchain-ollama~=0.3.5
- langchain-text-splitters~=0.3.11

Removed files:
- ansible_ai_connect/ai/api/model_pipelines/langchain/ (entire directory)
  - configuration.py
  - pipelines.py
  - tests/test_pipeline.py

Refactored ollama module to be fully self-contained:

Configuration (ollama/configuration.py):
- Created OllamaConfiguration extending BaseConfig directly
- Created OllamaBasePipelineConfiguration
- Removed dependency on langchain configuration classes

Pipelines (ollama/pipelines.py):
- Created custom OllamaClient for direct Ollama API communication
- Moved all utility functions from langchain module:
  * message_to_string()
  * create_role_outline()
  * unwrap_role_answer()
  * unwrap_message_with_yaml_answer()
  * unwrap_playbook_answer()
  * unwrap_task_answer()
- Implemented all pipeline classes without langchain:
  * OllamaMetaData
  * OllamaCompletionsPipeline
  * OllamaPlaybookGenerationPipeline
  * OllamaRoleGenerationPipeline
  * OllamaRoleExplanationPipeline (returns "nop" health check - not implemented)
  * OllamaPlaybookExplanationPipeline

Tests (ollama/tests/test_pipelines.py):
- Migrated relevant tests from deleted langchain/tests/test_pipeline.py
- Added comprehensive test coverage for:
  * Unwrap functions (task, playbook, role, message parsing)
  * Completions pipeline with mocked requests.post
  * Playbook generation pipeline (with and without outline, custom prompt)
  * Role generation pipeline (with and without outline)
  * Playbook explanation pipeline (with custom prompt)
- All tests updated to mock requests.post instead of langchain's FakeListLLM
- Prevents AttributeError from patching non-existent symbols

Updated configuration:
- pyproject.toml: Removed langchain dependencies and pyright path
- requirements.txt: Regenerated without langchain (15 fewer packages)
- uv.lock: Regenerated without langchain dependencies
- .github/workflows/pyright.yml: Removed langchain from CI dependencies

All functionality preserved. Type checking passes with pyright.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@goneri goneri force-pushed the goneri/deps-remove-langchain-dependency_7621 branch from bec1719 to 83f5238 Compare February 12, 2026 20:05
@sonarqubecloud
Copy link

@goneri goneri merged commit dae7ebd into main Feb 12, 2026
12 of 13 checks passed
@goneri goneri deleted the goneri/deps-remove-langchain-dependency_7621 branch February 12, 2026 20:23
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.

3 participants

Comments