Skip to main content

LbAgents

LangGraph-based agent workflows plugged into LbAPI.

This package contains pure agent logic — graph definitions, prompt templates, state schemas, tools, and a Pydantic workflow registry. It has no infrastructure dependencies (no database, no HTTP server, no Celery). MCP tools are discovered at runtime and passed to graph factories by the host application (LbAPI).

Architecture

graph LR
    subgraph LbAgents ["LbAgents (this package)"]
        Registry[Workflow Registry]
        Factories[Graph Factories]
        Schemas[State Schemas]
        Prompts[Prompt Templates]
        Tools[GitLab Tools]
    end

    subgraph LbAPI ["LbAPI (host)"]
        Router["/agent/* router"]
        Celery[Celery tasks]
        MCP[MCP tool discovery]
        LLM[KServe LLM clients]
        PG[AsyncPostgresSaver]
        LF[Langfuse observability]
    end

    Router -->|imports| Registry
    Celery -->|builds graph from| Factories
    MCP -->|passes tools to| Factories
    LLM -->|passes LLMs to| Factories
    PG -->|compiles with| Factories

Key design decisions

  • Factory pattern: Graph factories return an uncompiled StateGraph. The caller (LbAPI) compiles it with a checkpointer.
  • Tools as parameters: Factories accept a tools list — no hardcoded tool definitions. LbAPI discovers MCP tools at runtime and combines them with GitLab tools from this package.
  • Self-registration: Importing LbAgents populates WORKFLOW_REGISTRY with all available workflows. Adding a new graph to this package makes it available in LbAPI with zero LbAPI code changes.
  • Write-tool interrupts: Tools that perform write operations (posting reviews, creating issues) are gated by human-in-the-loop interrupts. The pending tool call is shown to the reviewer before execution.

Workflows

Name Description Trigger Delivery Human Review
ap_debug_ci_failure Single-agent CI failure diagnosis and MR review Internal GitLab MR Before posting review
ap_debug_ci_failure_multiagent Multi-agent CI failure diagnosis with parallel investigation Internal GitLab MR Before posting review
ap_debug_stuck_productions Diagnose stuck productions (MaxReset, stalled files) Internal GitLab Issue Before write actions
mattermost_debug_user_request Answer user support questions via Mattermost Webhook Mattermost Always (admin verifies)
nightly_failure_summary Summarize nightly build test failures Manual — No

ap_debug_ci_failure

Single ReAct loop with one LLM (orchestrator). The agent investigates using pipeline MCP tools, reads the MR diff, and posts a review. Write operations require human approval.

graph TD
    A[agent] -->|tool calls| T[tools]
    T --> A
    A -->|no tool calls,\npost_mr_review not called| N[nudge]
    N --> A
    A -->|write tool call| HR[human_review\n— interrupt —]
    HR -->|approved| T
    HR -->|rejected + feedback| A
    HR -->|rejected| END
    A -->|no tool calls| END

ap_debug_ci_failure_multiagent

Multi-agent pipeline: triage identifies failures, parallel investigators diagnose each cluster, a synthesizer drafts the review, an optional code reviewer adds inline comments, and the review is posted after human approval.

graph TD
    TA[triage_agent] -->|tool calls| TT[triage_tools]
    TT --> TA
    TA -->|done| CJ[collect_job_info]
    CJ --> CL[cluster_jobs]

    CL -->|"Send() per cluster\n(parallel)"| IJ[investigate_job]
    CL -->|no clusters| SA

    IJ -->|optional| RF[review_findings\n— interrupt —]
    IJ --> SA[synthesize_agent]
    RF --> SA

    SA -->|tool calls| ST[synthesize_tools]
    ST --> SA
    SA -->|done| SRB[save_review_body]

    SRB -->|"MR + code review tools"| RC["review_code\n(Send)"]
    SRB -->|no code review| PPR
    SRB -->|no MR| END

    RC --> MCR[merge_code_review]
    MCR --> PPR[prepare_post_review]

    PPR --> HR[human_review\n— interrupt —]
    HR -->|approved| EPR[execute_post_review]
    HR -->|rejected + feedback| SA
    HR -->|rejected| END
    EPR --> END

    style HR fill:#f9f,stroke:#333
    style RF fill:#f9f,stroke:#333

ap_debug_stuck_productions

Single ReAct agent investigating a stuck production sample. Uses production MCP tools (sample details, MaxReset files, grid job logs). Write actions (adding known failures, creating GitLab issues) require human approval.

graph TD
    A[agent] -->|tool calls| T[tools]
    T --> A
    A -->|write tool call| HR[human_review\n— interrupt —]
    HR -->|approved| T
    HR -->|rejected + feedback| A
    HR -->|rejected| END
    A -->|no tool calls| END

mattermost_debug_user_request

Support bot triggered by admin in a Mattermost thread. Investigates using all available tools, drafts a response, then always pauses for admin verification before posting.

graph TD
    A[agent] -->|tool calls| T[tools]
    T --> A
    A -->|done| HV[human_verify\n— interrupt —]
    HV --> END

nightly_failure_summary

Simple ReAct agent that queries nightly build test results and produces a structured summary. Read-only — no interrupts.

graph TD
    A[agent] -->|tool calls| T[tools]
    T --> A
    A -->|done| END

Tools

GitLab tools (LbAgents.tools.gitlab)

Factory function make_gitlab_review_tools(gitlab_token, mr_iid) returns LangChain tools scoped to a specific merge request:

  • get_mr_info() — MR metadata (title, author, branches, labels)
  • get_mr_diff() — File-level diffs
  • get_mr_file_content(file_path) — Full file from source branch
  • post_mr_review(body, inline_comments) — Post review with inline comments
  • get_mr_commits() — Commit list for the MR
  • get_commit_diff(sha) — Diff for a specific commit
  • get_target_branch_file(file_path) — File from the target branch

Nightly tools (LbAgents.tools.nightly)

Factory function make_nightly_tools(bucket_url) returns tools for querying nightly build results:

  • get_nightly_status_summary(slot, build_id) — Overall build status
  • list_nightly_platforms(slot, build_id) — Available platforms
  • list_nightly_projects(slot, build_id, platform) — Projects for a platform
  • get_failed_tests(slot, build_id, platform, project) — Failed test list
  • get_test_output(slot, build_id, platform, project, test) — Test output
  • get_test_measurement(slot, build_id, platform, project, test) — Performance data

Usage

from LbAgents import WORKFLOW_REGISTRY
from LbAgents.tools.gitlab import make_gitlab_review_tools

# All workflows are registered at import time
for name, spec in WORKFLOW_REGISTRY.items():
    print(f"{name}: {spec.description}")

# Build a graph with MCP tools + GitLab tools
from LbAgents.graphs import build_ap_debug_ci_failure_multiagent_graph

gitlab_tools = make_gitlab_review_tools(gitlab_token="...", mr_iid=42)
all_tools = mcp_tools + gitlab_tools

graph = build_ap_debug_ci_failure_multiagent_graph(
    orchestrator_llm=orchestrator,
    tools=all_tools,
    write_tool_names=["post_mr_review"],
    coder_llm=coder,  # optional, for code trace + review
)
compiled = graph.compile(checkpointer=my_checkpointer)

Adding a new workflow

  1. Create a new module in src/LbAgents/graphs/ with a build_*_graph() factory function.
  2. Add a state schema in src/LbAgents/schemas/state.py if needed.
  3. Add a prompt template in src/LbAgents/prompts/templates.py.
  4. Register the workflow in src/LbAgents/graphs/__init__.py via register_workflow().
  5. Add tests in tests/test_graphs.py.

The workflow will automatically appear in LbAPI's GET /agent/workflows endpoint.

Development

pixi install
pixi run pytest        # Run tests
pixi run ruff check    # Lint
pixi run pre-commit

License

GPL-3.0 — see COPYING.

Metadata

Release files for lbagents 0.18.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lbagents 0.18.10
File Size Uploaded Provenance Actions
lbagents-0.18.10.tar.gz 170.6 kB Without provenance Details for lbagents-0.18.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lbagents 0.18.10
File Interpreter ABI Platform Actions
lbagents-0.18.10-py3-none-any.whl Python 3 none any Details for lbagents-0.18.10-py3-none-any.whl

Total release size: 258.9 kB

Release files / lbagents-0.18.10.tar.gz

Download URL lbagents-0.18.10.tar.gz
Size 170.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d9df2426b39b4f8fc1a71dc1d1ca381ef6177ecf8a3df1ac933df58c989a63c6
BLAKE2b-256 checksum
How to use checksums
38cc211b0bfe42ab014b623aaa5fe0a7b68b304c00be9949dc1abac1d5a82c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / lbagents-0.18.10-py3-none-any.whl

Download URL lbagents-0.18.10-py3-none-any.whl
Size 88.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e68f16195802bf8aea92a5a4e02a7df7d879528a986d0b602e7373575e87ee0
BLAKE2b-256 checksum
How to use checksums
b3d2e560c38fe0105ab4aa26a6e035f6ed8f69e9fd9d3facd097bbd127c4744d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for lbagents 0.18.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page