Skip to content

Conversation

@Focadecombate
Copy link
Contributor

@Focadecombate Focadecombate commented Jan 21, 2026

User description

Shortcut: sc-50521

Description:

Adds support for LangChain's new Agent Middleware API, enabling Galileo observability for LangGraph agents through the GalileoMiddleware class.

Changes:

  • New GalileoMiddleware class (src/galileo/handlers/langchain/middleware.py): Implements the AgentMiddleware interface to provide tracing for:
    • Agent lifecycle (before_agent/after_agent and async variants)
    • Model calls (wrap_model_call/awrap_model_call)
    • Tool calls (wrap_tool_call/awrap_tool_call)
  • Both sync and async handlers: Uses GalileoBaseHandler and GalileoAsyncBaseHandler for full sync/async support
  • Automatic root node management: Creates and manages agent span hierarchy automatically
  • Support for ingestion hooks: Allows custom processing of trace data before ingestion
  • Added langchain as an optional dependency in pyproject.toml

Usage:

from galileo.handlers.langchain import GalileoMiddleware

middleware = GalileoMiddleware(galileo_logger=logger)
agent = create_agent(model, middleware=[middleware])

Tests:

  • Unit Tests Added
  • E2E Test Added (if it's a user-facing feature, or fixing a bug)

Test Coverage:

  • 34 unit tests covering:
    • Initialization (default and custom parameters)
    • Serialization helpers (messages, state, tools, responses)
    • Model metadata extraction
    • Parameter preparation for model/tool calls
    • Root node management (sync and async)
    • Agent lifecycle methods (sync and async)
    • Wrap methods for model and tool calls
    • Edge cases (empty responses, multiple sequential runs)
    • Ingestion hook integration

Generated description

Below is a concise technical summary of the changes proposed in this PR:
Implements the GalileoMiddleware class to support LangChain's new Agent Middleware API, ensuring continued observability for LangGraph agents. Integrates both sync and async handlers to manage agent span hierarchies and lifecycle events automatically.

TopicDetails
Agent Middleware Introduces the GalileoMiddleware class in src/galileo/handlers/langchain/middleware.py to handle agent lifecycle events, model calls, and tool calls for both sync and async flows.
Modified files (2)
  • src/galileo/handlers/langchain/middleware.py
  • tests/test_langchain_middleware.py
Latest Contributors(0)
UserCommitDate
Project Config Updates pyproject.toml and dependency locks to include langchain as an optional dependency and ensures compatibility with the new middleware requirements.
Modified files (4)
  • .github/workflows/codeflash.yaml
  • .pre-commit-config.yaml
  • poetry.lock
  • pyproject.toml
Latest Contributors(2)
UserCommitDate
vamaq@users.noreply.gi...refactor-Update-Traces...January 09, 2026
dmcwhorter@users.norep...feat-remove-python-3.9...January 05, 2026
This pull request is reviewed by Baz. Review like a pro on (Baz).

@Focadecombate Focadecombate requested a review from a team as a code owner January 21, 2026 18:01
@Focadecombate Focadecombate changed the title Feature/sc 50521/add langchain agent middleware support to feat: add langchain agent middleware Jan 21, 2026
@Focadecombate Focadecombate force-pushed the feature/sc-50521/add-langchain-agent-middleware-support-to branch from fa02c2f to 348e677 Compare January 21, 2026 18:06
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 93.22917% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.43%. Comparing base (e64d9d0) to head (e5c299b).

Files with missing lines Patch % Lines
src/galileo/handlers/langchain/middleware.py 93.22% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #457      +/-   ##
==========================================
+ Coverage   82.18%   82.43%   +0.24%     
==========================================
  Files          92       93       +1     
  Lines        8506     8698     +192     
==========================================
+ Hits         6991     7170     +179     
- Misses       1515     1528      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@savula15
Copy link
Contributor

Can we please ensure to address baz optimization and edge cases comments.

@Focadecombate Focadecombate force-pushed the feature/sc-50521/add-langchain-agent-middleware-support-to branch from 10d15b9 to e5c299b Compare January 23, 2026 21:29
@Focadecombate Focadecombate enabled auto-merge (squash) January 23, 2026 21:38
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