Skip to main content

4. Frameworks & Tech Stack

Building production agents requires choosing the right framework and understanding how to implement core patterns. This section compares major frameworks and provides detailed Spring AI implementation guides for Java/Spring Boot developers.


4.1 Framework Comparison

Overview of Major Frameworks

Comparison Matrix

FrameworkLanguageMaturityMulti-AgentStatefulBest For
Spring AIJavaGrowingBasicYesEnterprise Java
LangChainPythonMatureBasicLimitedQuick prototyping
LangGraphPythonGrowingExcellentYesComplex workflows
Microsoft Agent FrameworkPython/.NETLTSExcellentYesProduction agents (replaces AutoGen + Semantic Kernel)
OpenAI Agents SDKPythonGrowingGoodYesSandbox-native agent orchestration
CrewAIPythonMatureExcellentYesRole-based agents
LangChain4jJavaGrowingBasicYesJava port of LangChain
Google ADKPythonGrowingGoodYesGemini-native agents (2.0 at Cloud Next '26)
Claude Agent SDKPythonGrowingGoodYesClaude-native agents

|> April 2026 Update: Microsoft shipped Agent Framework 1.0 (April 7, 2026), officially unifying AutoGen and Semantic Kernel into a single LTS SDK for .NET and Python. Native MCP support, durable workflows, and a browser-based DevUI are included. AutoGen as a standalone project is now deprecated — migrate to Microsoft Agent Framework. OpenAI's Agents SDK (April 15 update) introduced sandbox execution and a model-native harness, making it a strong choice for GPT-model-based agent workflows.

Additional April 2026 developments:

  • Microsoft Agent Governance Toolkit (April 3, MIT license): Open-source runtime security covering all 10 OWASP Agentic AI risks with sub-0.1ms policy enforcement. Framework-agnostic — integrates with LangGraph, OpenAI Agents SDK, LlamaIndex, PydanticAI, Dify. Includes Agent OS (policy engine), Agent Mesh (cryptographic identity), Agent Runtime (privilege rings, kill switch), Agent SRE (SLOs, circuit breakers), and Agent Compliance (EU AI Act, HIPAA, SOC2 mapping).
  • Anthropic Managed Agents (mid-April): A service layer providing sandboxing, permissions, error recovery, and audit trails — absorbing the operational "grunt work" of running agents in production. Agent infrastructure is becoming a commodity.
  • Windows 11 AI Agents (April 18): Microsoft bringing agents to the Windows 11 taskbar via MCP for third-party agent integration.
  • Google Gemini Enterprise Agent Platform (April 22, Cloud Next '26): Vertex AI 重新品牌为企业级 Agent 平台,集成 Agent Designer(可视化工作流编辑器)、Agent Engine(会话持久化与记忆)、Agent Garden(预构建 Agent 模板)、Model Garden(200+ 模型含 Gemini、Claude、Llama)。新增 Express 免费层降低入门门槛。同时推出 Workspace Studio,允许业务用户用自然语言在 Google Workspace 中构建自动化 Agent。
  • Google ADK 2.0 (Cloud Next '26): Agent Development Kit 重大更新,与 Gemini Enterprise Agent Platform 深度集成,支持 Gemini-native 和第三方模型。
  • Anthropic Project Glasswing (April 22): 联合 AWS、Apple、Google、Microsoft、NVIDIA 等 40+ 组织的安全联盟。Claude Mythos(未发布前沿模型)展现了突破性的漏洞发现能力,但不会公开发布。

|> May 2026 developments:

  • LongSeeker: Context-ReAct 弹性上下文编排(arXiv, May 6): 提出五种原子操作(Skip、Compress、Rollback、Snippet、Delete)动态管理 Agent 工作记忆,在 BrowseComp 上达到 61.5%,大幅超越现有方案。基于 Qwen3-30B-A3B 微调,代表了长周期搜索 Agent 的新范式。
  • Uno-Orchestra: 多 Agent 统一编排策略(arXiv, May 6): 使用强化学习联合优化任务分解、Worker/模型选择和推理预算,在 13 个基准上达到 77.0% macro pass@1(比最强基线高 16%),单次查询成本降低约 10 倍。
  • DecodingTrust-Agent Platform (DTap)(arXiv, May 6): 首个可控、交互式 AI Agent 红队测试平台,覆盖 14 个真实领域和 50+ 模拟环境(Google Workspace、PayPal、Slack),系统性发现提示注入、工具注入、技能注入等攻击向量。
  • Design Conductor 2.0(arXiv, May 6): 多 Agent 系统在 80 小时内构建 TurboQuant 推理加速器,展示了 Agent 在硬件设计领域的突破性应用。
  • Anthropic Claude "Dreaming": Anthropic 开始让 Claude 在会话间隙"做梦"——回顾历史会话发现模式并自我改进,同时大幅提升使用限额。
  • DeepMind AlphaEvolve: Google DeepMind 的进化编码 Agent,结合进化搜索与 LLM 代码生成用于科学发现,已在多个领域产生实际影响。
  • Zerostack(HN, May 17): 受 Unix 哲学启发的纯 Rust 编码 Agent,以可组合、最小化为设计理念,在 HN 上获得 518 点关注,代表了轻量级 Agent 架构的新方向。GitHub
  • Oppo X-OmniClaw(May 17): Oppo 开源的端侧 Android Agent,融合摄像头、屏幕和语音交互。推理阶段仅使用云端计算,触控路径可克隆为可复用技能。完全开源。
  • Orchard(arXiv 2605.15040, May 14): 新的开源 Agentic 建模框架,提供端到端的 Agent 构建管线和标准化抽象。
  • APWA(arXiv 2605.15132, May 14): 分布式并行 Agentic 工作流架构,支持 Agent 任务的并行化调度和分布式执行。
  • FAMA(arXiv 2604.25135, April 28): 面向开源 LLM 工具使用的故障感知元 Agentic 框架,在工具调用场景中显著提升鲁棒性。
  • OpenAI 重组(May 17): OpenAI 围绕"Agentic Future"进行产品重组。Greg Brockman 接管产品策略,Thibault Sottiaux 领导核心产品团队,计划将 Codex、ChatGPT 和 Atlas 浏览器整合为"超级应用"。
  • Docker AI Governance + MCP Catalogs(May 12-15): Docker 推出 AI Agent 治理框架(沙箱策略、凭证治理、MCP 工具控制)和企业级 MCP Catalogs 与 Profiles,支持集中管理 AI 工具集。

Feature Comparison

FeatureSpring AILangGraphMicrosoft Agent FrameworkOpenAI Agents SDK
Tool Calling✅ Native✅ Native✅ Native✅ Native
Memory Management✅ Strong✅ Strong✅ Good✅ Basic
Multi-Agent⚠️ Basic✅ Excellent✅ Good✅ Excellent
State Persistence✅ Yes✅ Excellent✅ Good✅ Basic
Observability✅ Spring Boot Actuator✅ LangSmith✅ Telemetry⚠️ Basic
Enterprise Support✅ Excellent⚠️ Limited✅ Good⚠️ Limited

4.2 Spring AI Deep Dive

Spring AI provides the most seamless experience for Java/Spring Boot developers building agent systems.

Architecture

Project Setup

Dependencies (build.gradle)

dependencies {
// Spring AI OpenAI
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0'

// Spring AI MCP
implementation 'org.springframework.ai:spring-ai-mcp-spring-boot-starter:1.0.0'

// Spring AI Vector Store (PostgreSQL + pgvector)
implementation 'org.springframework.ai:spring-ai-pgvector-store-spring-boot-starter:1.0.0'

// Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// Environment variables (Doppler integration)
developmentOnly 'io.github.c-d-m:spring-boot-doppler:0.1.0'
}

Configuration (application.yml)

spring:
ai:
openai:
api-key: ${OPENAI_API_KEY}
chat:
options:
model: gpt-4o
temperature: 0.7

mcp:
servers:
- name: filesystem
transport:
type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-filesystem"
- /allowed/path

vectorstore:
pgvector:
dimension: 1536
distance-type: cosine
index-type: ivfflat

# Actuator for observability
management:
endpoints:
web:
exposure:
include: health,metrics,httptrace
tracing:
sampling:
probability: 1.0

Core Components

1. ChatClient Configuration

@Configuration
public class ChatClientConfig {

@Bean
public ChatClient chatClient(OpenAiChatModel model) {
return ChatClient.builder(model)
.defaultSystem("You are a helpful AI assistant with access to tools.")
.defaultOptions(OpenAiChatOptions.builder()
.model("gpt-4o")
.temperature(0.7)
.build())
.build();
}
}

2. Tool Definition

@Component
public class AgentTools {

@Autowired
private SearchService searchService;

@Autowired
private DatabaseService databaseService;

@Bean
public FunctionCallback searchTool() {
return FunctionCallback.builder()
.function("search_web", this::searchWeb)
.description("Search the web for current information")
.inputType(SearchRequest.class)
.build();
}

@Bean
public FunctionCallback databaseQueryTool() {
return FunctionCallback.builder()
.function("query_database", this::queryDatabase)
.description("Query the database for structured data")
.inputType(DatabaseQuery.class)
.build();
}

public record SearchRequest(
@Description("The search query string") String query,
@Description("Number of results to return") @DefaultValue("5") int numResults
) {}

public String searchWeb(SearchRequest request) {
return searchService.search(request.query(), request.numResults());
}

public record DatabaseQuery(
@Description("SQL query to execute") String sql
) {}

public String queryDatabase(DatabaseQuery query) {
return databaseService.executeQuery(query.sql());
}
}

3. Memory Configuration

@Configuration
public class MemoryConfig {

@Bean
public ChatMemory bufferMemory() {
return new MessageWindowChatMemory(10); // Last 10 messages
}

@Bean
public ChatMemory vectorMemory(VectorStore vectorStore) {
return new VectorStoreChatMemory(vectorStore);
}

@Bean
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
return new PgVectorStore(jdbcTemplate, embeddingModel);
}
}

Complete Agent Implementation

ReAct Agent with Spring AI

@Service
public class ReactAgentService {

@Autowired
private ChatClient chatClient;

@Autowired
private List<FunctionCallback> tools;

@Autowired
private ChatMemory memory;

public String execute(String query, int maxIterations) {
AgentContext context = new AgentContext(query, memory);

for (int i = 0; i < maxIterations; i++) {
// Generate thought and decide action
AgentResponse response = thinkAndAct(context);

// Check if agent wants to answer directly
if (response.isFinal()) {
return response.getContent();
}

// Execute tool
String toolResult = executeTool(response.getToolCall());

// Add to context
context.addObservation(toolResult);

// Update memory
memory.add(response.getMessage());
}

return "Max iterations reached";
}

private AgentResponse thinkAndAct(AgentContext context) {
return chatClient.prompt()
.messages(context.getMessages())
.functions(tools)
.call()
.entity(AgentResponse.class);
}

private String executeTool(ToolCall call) {
FunctionCallback tool = findTool(call.name());
return tool.call(call.arguments());
}

private FunctionCallback findTool(String name) {
return tools.stream()
.filter(t -> t.getName().equals(name))
.findFirst()
.orElseThrow();
}
}

REST Controller

@RestController
@RequestMapping("/api/agents")
public class AgentController {

@Autowired
private ReactAgentService reactAgent;

@PostMapping("/chat")
public ResponseEntity<ChatResponse> chat(@RequestBody ChatRequest request) {
String response = reactAgent.execute(
request.getMessage(),
request.getMaxIterations()
);

return ResponseEntity.ok(new ChatResponse(response));
}

@PostMapping("/stream")
public Flux<String> chatStream(@RequestBody ChatRequest request) {
return reactAgent.executeStream(request.getMessage())
.map(chunk -> "data: " + chunk + "\n\n");
}
}

Multi-Agent Implementation

Supervisor Pattern with Spring AI

@Service
public class SupervisorAgent {

@Autowired
private ChatClient chatClient;

@Autowired
private Map<String, WorkerAgent> workers;

@Autowired
private ChatMemory memory;

public String supervise(String task) {
SupervisorState state = new SupervisorState(task, memory);

for (int iteration = 0; iteration < 10; iteration++) {
// Supervisor decides next worker and task
String decision = chatClient.prompt()
.messages(state.getMessages())
.system("""
You are a supervisor coordinating specialized workers.
Available workers: {workers}

Respond in JSON format:
{
"worker": "worker_name",
"task": "specific task for worker",
"done": false
}
""".formatted(
workers.keySet().stream().collect(Collectors.joining(", "))
))
.call()
.content();

SupervisorDecision supervisorDecision = parseDecision(decision);

// Check if done
if (supervisorDecision.isDone()) {
return supervisorDecision.getFinalAnswer();
}

// Execute worker
WorkerAgent worker = workers.get(supervisorDecision.getWorker());
String result = worker.execute(supervisorDecision.getTask());

// Update state
state.addWorkerResult(
supervisorDecision.getWorker(),
supervisorDecision.getTask(),
result
);
}

return state.synthesizeFinalAnswer();
}
}

Worker Agents

@Component("researcher")
public class ResearcherWorker implements WorkerAgent {

@Autowired
private ChatClient chatClient;

@Autowired
private SearchService searchService;

@Override
public String execute(String task) {
// Search for information
String searchResults = searchService.search(task);

// Analyze and summarize
return chatClient.prompt()
.system("You are a research specialist. Analyze search results and provide key findings.")
.user("""
Task: {task}
Search Results: {results}
""".formatted(task, searchResults))
.call()
.content();
}
}

@Component("writer")
public class WriterWorker implements WorkerAgent {

@Autowired
private ChatClient chatClient;

@Override
public String execute(String task) {
return chatClient.prompt()
.system("You are a professional writer. Create well-structured content.")
.user(task)
.call()
.content();
}
}

@Component("coder")
public class CoderWorker implements WorkerAgent {

@Autowired
private ChatClient chatClient;

@Override
public String execute(String task) {
return chatClient.prompt()
.system("You are an expert programmer. Write clean, efficient code.")
.user(task)
.call()
.content();
}
}

4.3 Other Frameworks

LangGraph (Python)

LangGraph excels at building stateful, multi-agent applications.

from langgraph.graph import StateGraph, END
from typing import TypedDict

class AgentState(TypedDict):
messages: list
next: str

def supervisor_node(state: AgentState):
# Decide which agent acts next
return {"next": "researcher"}

def researcher_node(state: AgentState):
# Research logic
return {"messages": ["Research results"]}

# Build graph
workflow = StateGraph(AgentState)
workflow.add_node("supervisor", supervisor_node)
workflow.add_node("researcher", researcher_node)

workflow.add_edge("supervisor", "researcher")
workflow.add_edge("researcher", "supervisor")

workflow.set_entry_point("supervisor")
app = workflow.compile()

Semantic Kernel (C#)

Microsoft's Semantic Kernel integrates well with .NET ecosystem.

// Build kernel
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion("gpt-4", apiKey)
.Build();

// Add plugin
kernel.ImportPluginFromObject(new WebSearchPlugin());

// Run agent
var result = await kernel.InvokePromptAsync(
"Search for latest AI news and summarize"
);

OpenAI Agents SDK (2025.2)

OpenAI 于 2025年2月发布的官方 Agent 框架,提供轻量级、原生的 Agent 构建体验。

核心概念

ConceptDescription
Agents带有指令(instructions)和工具(tools)的 LLM 封装,是基本的执行单元
HandoffsAgent 间的任务转移机制,支持将对话路由到最合适的 Agent
Guardrails输入/输出的安全检查,支持自定义验证规则
Tracing内置运行追踪,支持可视化调试和性能分析

代码示例(Python)

from agents import Agent, Runner, function_tool

@function_tool
def get_weather(city: str) -> str:
return f"Weather in {city}: Sunny, 22°C"

agent = Agent(
name="Weather Agent",
instructions="You are a helpful weather assistant.",
tools=[get_weather],
)

result = Runner.run_sync(agent, "What's the weather in Tokyo?")
print(result.final_output)

特点

  • 原生支持 OpenAI 模型(GPT-4o 等)
  • 与 OpenAI API 深度集成,开箱即用
  • 支持多 Agent 编排(通过 Handoffs)
  • 内置 Tracing 支持(可接入 OpenAI Dashboard)

Google Agent Development Kit (ADK) (2025.4)

Google 于 2025年4月发布的开源 Agent 开发工具包,专为 Gemini 模型生态设计。

核心特性

FeatureDescription
声明式 Agent 定义通过配置和注解定义 Agent 行为,减少样板代码
内置工具集成原生支持 Google Search、Code Execution、Vertex AI 等
多 Agent 编排支持多 Agent 协作和层级式任务分配
评估框架内置 Agent 行为评估和基准测试工具

特点

  • 支持 Python,深度集成 Gemini 模型
  • 开源(Apache 2.0 许可)
  • 可部署到 Google Cloud(Vertex AI Agent Engine)
  • 目前处于早期阶段(Early Access),API 可能变更

注意:Google ADK 目前处于早期阶段,建议关注官方仓库获取最新更新。

Claude Agent SDK (Anthropic)

Anthropic 发布的 Agent SDK,为 Claude 模型提供原生的 Agent 构建能力,支持工具调用、多步推理和持久化工作流。

核心特性

FeatureDescription
Tool Use原生支持 Claude 的 tool_use 功能,定义 JSON Schema 工具
Multi-turn Conversation自动管理多轮对话上下文和工具调用循环
Streaming支持实时流式输出,包括 thinking 和 tool_use 事件
Guardrails输入/输出验证,可自定义安全检查规则

代码示例(Python)

import anthropic

client = anthropic.Anthropic()

# Define tools
tools = [
{
"name": "get_weather",
"description": "Get weather for a city",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
]

# Agent loop
messages = [{"role": "user", "content": "What's the weather in Tokyo?"}]

while True:
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=tools,
messages=messages,
)

# Check if agent wants to use a tool
if response.stop_reason == "tool_use":
# Execute tool and continue
tool_result = execute_tool(response)
messages.append({"role": "assistant", "content": response.content})
messages.append({"role": "user", "content": tool_result})
else:
print(response.content[0].text)
break

特点

  • 原生 Claude 模型集成,支持 Claude 4 系列
  • 可与 MCP(Model Context Protocol)无缝结合
  • 支持 prompt caching 降低延迟和成本
  • 提供 Claude Code CLI 工具用于编程场景

提示:Claude Agent SDK 的核心是 Anthropic Messages API 的 tool_use 能力。结合 MCP 协议可以快速构建具有丰富工具的 Agent 系统。详见 MCP Module


4.4 Development Tools

Observability & Debugging

ToolPurposeIntegration
LangSmithDebug & trace LangChainBuilt-in with LangGraph
Spring Boot ActuatorMetrics & tracingNative with Spring AI
Arize PhoenixLLM observabilityOpenTelemetry integration
PromptLayerPrompt versioningAPI wrapper

Spring Boot Actuator Setup

# application.yml
management:
endpoints:
web:
exposure:
include: health,metrics,prometheus,httptrace
metrics:
export:
prometheus:
enabled: true
tracing:
sampling:
probability: 1.0

OpenTelemetry Integration

@Configuration
public class TracingConfig {

@Bean
public OpenTelemetry openTelemetry() {
return OpenTelemetrySdk.builder()
.setTracerProvider(
SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(
OtlpGrpcSpanExporter.builder()
.setEndpoint("http://localhost:4317")
.build()
).build())
.build()
)
.buildAndRegisterGlobal();
}
}

4.5 Complete Example: Research Agent

Project Structure

research-agent/
├── src/main/java/com/portfolio/agent/
│ ├── config/
│ │ ├── ChatClientConfig.java
│ │ ├── MemoryConfig.java
│ │ └── ToolConfig.java
│ ├── controller/
│ │ └── AgentController.java
│ ├── service/
│ │ ├── ReactAgentService.java
│ │ └── SupervisorAgentService.java
│ ├── tools/
│ │ ├── SearchTool.java
│ │ ├── DatabaseTool.java
│ │ └── FileTool.java
│ └── Application.java
├── src/main/resources/
│ └── application.yml
└── build.gradle

Main Application

@SpringBootApplication
@EnableScheduling
public class ResearchAgentApplication {

public static void main(String[] args) {
SpringApplication.run(ResearchAgentApplication.class, args);
}
}

Request/Response DTOs

public record ChatRequest(
String message,
@DefaultValue("5") int maxIterations
) {}

public record ChatResponse(
String response,
int iterations,
List<String> toolsUsed
) {}

Testing

@SpringBootTest
@AutoConfigureMockMvc
class AgentControllerTest {

@Autowired
private MockMvc mockMvc;

@Test
void testChatEndpoint() throws Exception {
String request = """
{"message": "What's the latest news about AI?"}
""";

mockMvc.perform(post("/api/agents/chat")
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.andExpect(status().isOk())
.andExpect(jsonPath("$.response").exists());
}
}

4.6 Key Takeaways

Framework Selection

Use CaseRecommended Framework
Java EnterpriseSpring AI
Python PrototypingLangChain
Complex Multi-AgentLangGraph
Microsoft StackMicrosoft Agent Framework (replaces Semantic Kernel / AutoGen)
GPT-based AgentsOpenAI Agents SDK
Role-based TeamsCrewAI
Gemini/Google CloudGoogle ADK
Claude-native AgentsClaude Agent SDK
企业级团队 Agent 平台Runtime(YC P26)

2026年5月动态

Anthropic Claude Managed Agents(Code with Claude 2026 大会,May 6-19): Anthropic 发布 Managed Agents 三大新能力:

  • Multi-Agent Orchestration: Lead Agent 将任务拆解后委派给专家子 Agent 并行执行,每个子 Agent 可配置独立的模型、Prompt 和工具集
  • Outcomes: 定义评分标准(Rubric),独立评分 Agent 对输出质量把关。测试显示 PPT 输出质量提升 10.1%,Word 文档提升 8.4%
  • Dreaming: 跨会话记忆调度机制,在会话间自动提取模式、修复常见错误、优化工作流。类似开源 Hermes Agent 的 cron 机制

Google Gemini Spark(Google I/O 2026,May 20): Google 推出云端 AI Agent,可后台持续运行(设备锁屏也不中断),能自动整理邮件/会议纪要/待办事项,并在高敏感操作(发送邮件、购物)前请求用户确认。今夏将集成 Chrome 浏览器

来源:Anthropic Code with Claude 2026Google I/O 2026

Spring AI Advantages

  1. Native Spring Integration: Seamless with Spring Boot
  2. Type Safety: Strong typing with records
  3. Dependency Injection: Easy testing and configuration
  4. Observability: Built-in with Actuator
  5. Enterprise Support: Production-ready features

Best Practices

  1. Environment Variables: Use Doppler for secrets
  2. Structured Output: Use records for type safety
  3. Memory Management: Choose appropriate memory type
  4. Error Handling: Robust tool execution
  5. Testing: Mock tools for unit tests

4.7 Next Steps

Now that you have the framework knowledge:

For Deeper Learning:

For Production:

For Future:


Start with Spring AI

If you're a Java/Spring Boot developer, Spring AI provides the smoothest path to building production agents. See the complete examples above for implementation patterns.

Environment Management

Remember to use Doppler for all environment variables. Never hardcode API keys or secrets in your codebase.