Skip to content

feat(adk): expose current messages to middleware - #1164

Open
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-868-get-agent-messages
Open

feat(adk): expose current messages to middleware#1164
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-868-get-agent-messages

Conversation

@March-77

Copy link
Copy Markdown

What type of PR is this?

feat

Check the PR title.

  • This PR title matches the required format.
  • The description is user-oriented and clear.
  • No separate documentation PR is required; the new API has Go documentation.

(Optional) Translate the PR title into Chinese.

feat(adk): 向中间件开放当前消息列表

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

ChatModelAgent middleware hooks that do not receive TypedChatModelAgentState currently have no first-class way to inspect the current message list. Consumers must reach into compose.ProcessState and the deprecated concrete adk.State; this is impossible for AgenticMessage because its internal state type is intentionally unexported.

This change adds:

  • GetMessages(ctx) for the standard *schema.Message path
  • TypedGetMessages[M](ctx) for both supported message types
  • a shallow snapshot contract so changing the returned slice cannot mutate agent state
  • clear errors when called outside an active ChatModelAgent execution

The skill middleware now consumes the public API instead of deprecated/internal state details, which also removes its message-state access restriction for the Agentic path.

User impact: middleware and tool hooks can inspect current messages without depending on compose internals. Existing APIs and behavior are unchanged.

Compatibility/risk: additive public API only. Message objects are intentionally shared and documented as read-only; only the returned slice is copied.

Validation:

  • go test ./adk -run "TestGetMessages|TestAgenticChatModelAgentRun_WithMiddleware" -count=10
  • go test -race ./adk -run "TestGetMessages|TestAgenticChatModelAgentRun_WithMiddleware" -count=1
  • go test ./adk/middlewares/skill
  • go test ./adk
  • go test ./...
  • go vet ./...

golangci-lint could not be completed locally because the pinned runner repeatedly stalled while downloading github.com/MirrexOne/unqueryvet v1.5.4.

(Optional) Which issue(s) this PR fixes:

Fixes #868

@March-77

Copy link
Copy Markdown
Author

Revalidation update (2026-08-23): this remains mergeable against current main (ebd616c), with no equivalent GetMessages/TypedGetMessages API on main or alpha/10. The two main commits since this PR's base touch unrelated middleware packages.

Local validation passes:

  • go test ./adk ./adk/middlewares/skill
  • go test -race ./adk -run 'TestGetMessages|TestAgenticChatModelAgentRun_WithMiddleware' -count=1

The PR still matches the first-class API direction requested in #868 and removes the skill middleware's Agentic fork-mode restriction. GitHub Actions have never started for this fork PR (CLA is passing), so the blocked state is required review rather than a failing check. A maintainer review/workflow approval when convenient would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Provide means to access Messages for ChatModelAgentMiddleware

1 participant