Skip to content

[AI] AG-UI compliant Langgraph ReAct agent implementation#10612

Merged
ananzh merged 5 commits intoopensearch-project:mainfrom
ananzh:osd-agents
Oct 1, 2025
Merged

[AI] AG-UI compliant Langgraph ReAct agent implementation#10612
ananzh merged 5 commits intoopensearch-project:mainfrom
ananzh:osd-agents

Conversation

@goyamegh
Copy link
Contributor

@goyamegh goyamegh commented Sep 30, 2025

Description

This PR introduces the osd-agents package - an experimental reference implementation of an AG-UI compliant ReAct (Reasoning and Acting) agent built with LangGraph and AWS Bedrock.

What does this agent do?

The agent implements a reasoning loop that:

  • Reasons through problems step-by-step
  • Acts by dynamically discovering and calling tools via Model Context Protocol (MCP)
  • Observes tool results to inform next actions
  • Iterates until the task is complete

Key Features

  • AG-UI Protocol Compliance: Implements AG-UI standard for agent interactions
  • ReAct Pattern: LangGraph-based reasoning and action loop
  • Dynamic Tool Use: Runtime tool discovery via MCP servers (local stdio & remote HTTP)
  • Dual Operation Modes:
    • Interactive CLI for development/testing
    • HTTP server with streaming SSE for integration
  • AWS Bedrock Integration: Uses Claude models for reasoning
  • Comprehensive Logging: Audit logging, metrics, and LLM request tracking

Architecture Highlights

  • Agent Factory Pattern: Extensible architecture supporting multiple agent types (currently: ReAct)
  • MCP Integration Layer: Unified interface for local and remote MCP servers
  • AG-UI Adapters: Protocol translation between AG-UI messages and agent internals
  • Message Lifecycle Management: Proper handling of tool calls, interruptions, and streaming

What's Included

  • Complete ReAct agent implementation (src/agents/langgraph/)
  • MCP client infrastructure (stdio & HTTP)
  • AG-UI server with SSE streaming
  • Configuration management for MCP servers
  • Comprehensive logging and metrics
  • CLI and HTTP server entry points

Experimental Status

⚠️ This is an experimental reference implementation:

  • Not production-ready
  • Intended for learning, testing, and development
  • API stability not guaranteed
  • Limited testing coverage

Issues Resolved

RFC #10585
Can be used in conjunction with chat interface and client tools of context provider in #10600

Screenshot

TBD

Testing the changes

Tested with PR #10600

The agent can be tested via:

# Interactive CLI mode
npm start

# AG-UI HTTP server mode
npm run start:ag-ui

Requires:
- AWS Bedrock access with Claude model permissions
- MCP server configuration in configuration/mcp_config.json

Changelog

  • feat: [AI] AG-UI compliant Langgraph ReAct agent implementation

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@github-actions
Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

opensearch-changeset-bot bot added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Sep 30, 2025
@codecov
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.14%. Comparing base (3ac73b1) to head (4a99470).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10612   +/-   ##
=======================================
  Coverage   60.14%   60.14%           
=======================================
  Files        4425     4425           
  Lines      118370   118370           
  Branches    19443    19443           
=======================================
  Hits        71188    71188           
  Misses      42267    42267           
  Partials     4915     4915           
Flag Coverage Δ
Linux_1 26.65% <ø> (ø)
Linux_2 38.83% <ø> (ø)
Linux_3 38.62% <ø> (+<0.01%) ⬆️
Linux_4 32.59% <ø> (ø)
Windows_1 26.67% <ø> (ø)
Windows_2 38.80% <ø> (ø)
Windows_3 38.63% <ø> (+<0.01%) ⬆️
Windows_4 32.59% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -0,0 +1,3 @@
{
"modelId": "us.anthropic.claude-sonnet-4-20250514-v1:0"
Copy link
Member

Choose a reason for hiding this comment

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

does it perform better using claude sonnet 4.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will try it and share feedback


// Check for custom system prompt file path from environment variable
let customSystemPrompt: string | undefined;
const systemPromptPath = process.env.SYSTEM_PROMPT;
Copy link
Member

Choose a reason for hiding this comment

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

why not configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can take up as fat-follow

*/

import { StateGraph, START, END, Annotation } from '@langchain/langgraph';
import { SqliteSaver } from '@langchain/langgraph-checkpoint-sqlite';
Copy link
Member

Choose a reason for hiding this comment

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

can this use https://langchain-ai.github.io/langgraphjs/agents/agents/?h=memory+saver#5-add-memory

import { StateGraph, START, END, Annotation, MemorySaver } from '@langchain/langgraph';

and not introduce sqlite lib dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

hasAwsAccessKey: !!process.env.AWS_ACCESS_KEY_ID,
hasAwsSecretKey: !!process.env.AWS_SECRET_ACCESS_KEY,
hasAwsProfile: !!process.env.AWS_PROFILE,
hasAwsSessionToken: !!process.env.AWS_SESSION_TOKEN,
Copy link
Member

Choose a reason for hiding this comment

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

these are unnecessary logs? sdk should figure out where credentials come from

`;
prompt = prompt.replace('{{CLIENT_STATE}}', stateContent);
} else {
prompt = prompt.replace('{{CLIENT_STATE}}', '// No client state provided');
Copy link
Member

Choose a reason for hiding this comment

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

what is {{CLIENT_STATE}}? can this placeholder come from some constant?

would clientState ever be a complex/circular object that can't be stringified?

}`;

if (tool.inputSchema.required && tool.inputSchema.required.length > 0) {
toolDescription += `\n - Required parameters: ${tool.inputSchema.required.join(', ')}`;
Copy link
Member

Choose a reason for hiding this comment

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

the langgraph framework doesn't auto do this and requires us to manually build tool prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can check this and get back on it

ps48
ps48 previously approved these changes Oct 1, 2025
ananzh
ananzh previously approved these changes Oct 1, 2025
goyamegh and others added 4 commits September 30, 2025 23:57
Lint fixes and changing file to snake case

Fixing imports for snake case

feat: Implement TextMessageManager for improved message lifecycle management and tool call interruption in AG UI

feat: Refactor tool result handling to improve message lifecycle management in BaseAGUIAdapter

feat: Improve response handling by logging warnings for empty content blocks and filtering out empty text blocks to prevent ValidationException

Renaming text_message_manager and imports

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

Adding default observability prompt

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

Removing jarvis and coact agents

Signed-off-by: Megha Goyal <goyamegh@amazon.com>
Signed-off-by: Megha Goyal <goyamegh@amazon.com>
Signed-off-by: Megha Goyal <goyamegh@amazon.com>
@ananzh ananzh added ai Changes related to AI chat, context provider and artifact v3.3.0 Issues targeting release v3.3.0 OSD Changes being merged by the OSD team labels Oct 1, 2025
Signed-off-by: Megha Goyal <goyamegh@amazon.com>
Copy link
Member

@joshuali925 joshuali925 left a comment

Choose a reason for hiding this comment

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

didn't get to go through everything, but approving since it's a separate experimental package

"build": "tsc",
"clean": "find . -name '*.js' -not -path './node_modules/*' -delete",
"opensearch:ingest": "ts-node src/opensearch-ingestion.ts",
"opensearch:watch": "ts-node src/opensearch-ingestion.ts --watch"
Copy link
Member

Choose a reason for hiding this comment

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

file is opensearch_ingestion with underscore

@ananzh
Copy link
Member

ananzh commented Oct 1, 2025

Failed windows tests are known CI/CD issue that we observe in my PRs lately. There is a tracking fix #10613. Should not block PR due to these CI/CD issues.

Wait for the last cypress to re-run then we could merge the PR in.

@ananzh ananzh merged commit 681c9e6 into opensearch-project:main Oct 1, 2025
212 of 242 checks passed
yanatha99 pushed a commit to yanatha99/OpenSearch-Dashboards that referenced this pull request Oct 2, 2025
…-project#10612)

* AG-UI compliant Langgraph ReAct agent implementation

Lint fixes and changing file to snake case

Fixing imports for snake case

feat: Implement TextMessageManager for improved message lifecycle management and tool call interruption in AG UI

feat: Refactor tool result handling to improve message lifecycle management in BaseAGUIAdapter

feat: Improve response handling by logging warnings for empty content blocks and filtering out empty text blocks to prevent ValidationException

Renaming text_message_manager and imports

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

Adding default observability prompt

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

Removing jarvis and coact agents

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

* Changeset file for PR opensearch-project#10612 created/updated

* Fixing build failures due to langgraph-checkpoint-sqlite

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

* Fixing yarn.lock using yarn v1.22.10

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

* Fix yarn.lock aain for 1.22.10 after rebase

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

---------

Signed-off-by: Megha Goyal <goyamegh@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Nathan Yang <yanatha@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Changes related to AI chat, context provider and artifact OSD Changes being merged by the OSD team repeat-contributor v3.3.0 Issues targeting release v3.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants