CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

gamussa/langchain4j-agentic

Build and demo Java AI agent systems with langchain4j-agentic: workflow patterns, supervisor, custom Planner strategies (incl. the flagship typed-verdict / CriticResult-style critic pattern), plus MCP tools, A2A remote agents, build setup, and conference-demo storylines. Pinned to 1.15.0 / 1.15.0-beta25.

4.76x
Quality

89%

Does it follow best practices?

Impact

100%

4.76x

2 of 3 eval scenarios. Add 1 more for a full score.

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

SKILL.mdskills/langchain4j-agentic/

name:
langchain4j-agentic
description:
Build, scaffold, and demo Java AI agent systems with the langchain4j-agentic module — workflow patterns (sequential, loop, parallel, conditional), supervisor, and custom Planner strategies including the flagship typed-verdict (CriticResult-style) critic pattern, plus langchain4j-mcp tool servers and langchain4j-agentic-a2a remote agents. Use whenever the user mentions LangChain4j, langchain4j-agentic, Java AI agents, @Agent / @Tool, AgenticScope, AgenticServices, sequenceBuilder / loopBuilder / supervisorBuilder / plannerBuilder, MCP or A2A in Java, or wants to build a conference demo / workshop / POC around autonomous Java agents. Pinned to 1.15.0 core + 1.15.0-beta25 agentic/mcp; refresh with scripts/check_versions.sh.

LangChain4j Agentic — Java Agents & Demo Builder

Build agentic AI systems in Java with langchain4j-agentic: deterministic workflows, the LLM-driven supervisor, and custom Planner strategies — including the flagship typed-critic pattern this demo is built around. Extends to langchain4j-mcp (tools) and langchain4j-agentic-a2a (remote agents).

Use for LangChain4j Java agent work. Not for Spring AI, Google ADK-Java, raw Anthropic/OpenAI SDK without LangChain4j, or Python LangChain.

First action — pin versions

The module is experimental; builder names and coordinates drift between betas. Run scripts/check_versions.sh before writing build files. Confirmed current (2026-05-25, via maven-metadata.xml):

ArtifactVersionNotes
langchain4j-bom / langchain4j / -anthropic / -open-ai1.15.0GA; BOM aligns core only
langchain4j-agentic / -agentic-a2a / -agentic-patterns / -mcp1.15.0-beta25pin explicitly — NOT in the BOM

The stable BOM does not manage the beta artifacts — pin each independently or you get NoSuchMethodError at runtime. See docs/tools-memory-and-build.md.

⭐ The flagship pattern (lead with this)

The centerpiece is Custom Strategy with Domain Modeling — docs/custom-strategy-critic-result.md. A verifier agent returns a typed result object (illustrated as CriticResult — application code, not a framework type, and need not be generic) carrying a pass/fail verdict, feedback, and the typed payload, which deterministically drives Identify → Fix → Verify → Adjust: pass → finish emitting the typed payload; fail → adjust with the feedback, re-verify. Domain-modeling the object that flows between agents (instead of a bare double score) makes routing compile-checked and the success branch fully typed. When the user is building "the demo", this is the pattern to reach for.

Core mental model

  1. AgenticServices is the single factory. Static methods return a builder per pattern; everything is explicit construction. Full inventory in docs/index.md.
  2. @Agent decorates a method on an interface using @UserMessage/@SystemMessage/@V. Tools use the existing @Tool/@P from langchain4j-core — there is no agentic-specific tool annotation. Agents are AiServices with orchestration on top.
  3. AgenticScope is the shared blackboard. Agents publish via outputKey="k", downstream agents read via @V("k"). Created per top-level invocation; records invocation history.
  4. Workflows are deterministic; supervisors are not. sequence/loop/parallel/conditionalBuilder = fixed topology. supervisorBuilder hands control to an LLM planner. plannerBuilder = your own algorithmic strategy (the flagship lives here). Show the contrast on stage.
  5. Observability is first-class. AgentListener for hooks, AgentMonitor + HtmlReportGenerator.generateReport(monitor, Path) for an HTML topology+timeline — the framework's strongest visual moment.

Defaults unless the user overrides

  • Java 21, Gradle Kotlin DSL (assets/build.gradle.kts). Maven only on request.
  • Compile with -parameters — without it @V("name") binds null silently. Already set in the template.
  • Anthropic Claude Sonnet 4.5 primary, gpt-4o-mini ready as a hot-swap fallback. Bigger model for planners/critics, smaller for workers.
  • .maxSequentialToolsInvocations(10) is mandatory on any tool-using agent (runaway-loop guard).
  • MessageWindowChatMemory.withMaxMessages(20) when memory is needed.
  • Shutdown hook whenever using stdio MCP transport (orphan-subprocess guard).
  • End multi-agent examples with the HtmlReportGenerator one-liner.

Choosing a pattern

NeedUseDoc
Typed verify/adjust loop driven by a domain verdict⭐ custom Planner + typed verdict object (CriticResult-style)custom-strategy-critic-result.md
Fixed order, piping outputssequenceBuilderworkflow-patterns.md
Iterate until condition metloopBuilderworkflow-patterns.md
Independent agents concurrentlyparallelBuilder / parallelMapperBuilderworkflow-patterns.md
Route by conditionconditionalBuilderworkflow-patterns.md
Pause for human approvalhumanInTheLoopBuilderworkflow-patterns.md
LLM plans which agent runssupervisorBuilderpure-agentic.md
Goal-graph / peer-to-peer / votingplannerBuilder + Plannerpure-agentic.md
Annotation-driven definitiondeclarative APIdeclarative-api.md
External tools / remote agentsMCP toolProviders / a2aBuildermcp-and-a2a.md
Build/deps/tools/memory/models—tools-memory-and-build.md
Conference talk / workshopfour-act structuredemo-storylines.md
Debugging / stage rehearsaltop-10 risksgotchas.md

API-correctness notes (don't copy stale web examples)

  • AgentListener callbacks take AgentRequest/AgentResponse; inheritedBySubagents() defaults to false.
  • Planner is init/firstAction/nextAction returning Action via call(...)/done() helpers.
  • Supervisor SCORED uses a scorer agent ranking the summary vs. the last output — not "sub-agents return scores."
  • Canonical key methods are outputKey / typedOutputKey (older examples use .outputName(...)).

Bundled resources

  • assets/build.gradle.kts — Gradle Kotlin DSL build (BOM + explicit beta pins, both LLM clients, -parameters).
  • assets/App.java — ~80-line runnable bootstrap (one @Agent, two @Tools, AnthropicChatModel, AgentMonitor, HTML report).
  • scripts/check_versions.sh — query Maven Central for current GA + beta of every artifact.

Always cross-check generated code against the official source: langchain4j/docs/docs/tutorials/agents.md.

skills

langchain4j-agentic

README.md

tile.json