Skip to content

feat(harness): support passing business context from InboundMessage to RuntimeContext (#1966)#1967

Open
Buktal wants to merge 2 commits into
agentscope-ai:mainfrom
Buktal:feat/business-context-passing
Open

feat(harness): support passing business context from InboundMessage to RuntimeContext (#1966)#1967
Buktal wants to merge 2 commits into
agentscope-ai:mainfrom
Buktal:feat/business-context-passing

Conversation

@Buktal

@Buktal Buktal commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-SNAPSHOT

Related Issue

Closes #1966

Description

Add Map<String, Object> businessContext to InboundMessage to allow callers to pass
business parameters (e.g. tenantId, modelConfigId, datasourceId) through the channel/gateway
pipeline into RuntimeContext, eliminating the need for ConcurrentHashMap workarounds with
manual lifecycle management.

Key design decisions:

  • businessContext does NOT participate in canonicalKey() — session routing is unaffected
  • Kept separate from MsgContext.extra (which affects session routing)
  • Map<String, Object> provides flexibility for simple types; Javadoc recommends simple types
  • Builder API: .businessContext(Map) and .putBusinessParam(key, value) for convenience

Data flow:

Controller → InboundMessage.businessContext
  → ChannelRouter.resolveRoute() → MsgContext.businessContext (NOT in canonicalKey)
  → HarnessGateway.injectBusinessContext() → RuntimeContext.Builder.putAll()
  → Middleware/Tool: RuntimeContext.get("tenantId")

Changes:

  • InboundMessage: new businessContext field + Builder methods
  • MsgContext: new businessContext field + withBusinessContext(), NOT in canonicalKey()
  • ChannelRouter: propagates businessContext from InboundMessage to MsgContext
  • HarnessGateway: injectBusinessContext() in run() and runStream()
  • 3 new test files covering InboundMessage, MsgContext, and RouteResult propagation (33 tests)

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

…o RuntimeContext

Add Map<String, Object> businessContext field to InboundMessage, propagate it
through MsgContext and RouteResult, and inject it into RuntimeContext.Builder
via HarnessGateway so middlewares and tools can access caller-provided business
parameters (e.g. tenantId, modelConfigId, datasourceId).

- InboundMessage: new businessContext field + Builder.putBusinessParam()
- MsgContext: new businessContext field (not in canonicalKey())
- RouteResult: unchanged (businessContext accessible via .context())
- HarnessGateway: injectBusinessContext() in both run() and runStream()

Co-authored-by: 江宝坤 <jiangbaokun@kst.software>
@Buktal Buktal requested a review from a team June 30, 2026 03:13
@Buktal Buktal changed the title feat(harness): support passing business context from InboundMessage to RuntimeContext feat(harness): support passing business context from InboundMessage to RuntimeContext (#1966) Jun 30, 2026
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...entscope/harness/agent/gateway/HarnessGateway.java 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

[Feature]: Support passing custom context from InboundMessage to RuntimeContext

1 participant