Skip to content

Plumb EnableMessageInjection through provider AgentConfig so the message-injector loop is reachable - #652

Open
PratikDhanave (PratikDhanave) wants to merge 4 commits into
microsoft:mainfrom
PratikDhanaveFork:plumb-enable-message-injection
Open

Plumb EnableMessageInjection through provider AgentConfig so the message-injector loop is reachable#652
PratikDhanave (PratikDhanave) wants to merge 4 commits into
microsoft:mainfrom
PratikDhanaveFork:plumb-enable-message-injection

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

The toolautocall harness already fully implements Config.EnableMessageInjection and its MessageInjector loop (inject.go, wired in autocall.go, tested in autocall_inject_test.go, ported from .NET's MessageInjectingChatClient). However, no provider ever wired the flag: every provider built toolautocall.Config with only Logger/LogSensitiveData, so the message-injector loop was unreachable through the normal agent API.

This PR:

  • Adds EnableMessageInjection bool to agent.Config (in agent/agent.go), beside the existing DisableFuncAutoCall.
  • Passes EnableMessageInjection: config.EnableMessageInjection into each provider's guarded toolautocall.New(toolautocall.Config{...}) literal: openaiprovider (chat + responses), anthropicprovider, geminiprovider, and aguiprovider.

Because each provider AgentConfig embeds agent.Config and forwards config.Config to agent.New, the new field flows to all providers uniformly. Previously the only way to enable injection was DisableFuncAutoCall=true plus hand-rebuilding the middleware, which loses provider defaults.

Why (parity)

This mirrors the .NET MessageInjectingChatClient / EnqueueMessages surface, which is composable into the standard function-invocation pipeline. Exposing the flag on AgentConfig keeps the Go SDK aligned: tools can enqueue follow-up messages into the auto-call loop without opting out of the provider-managed middleware.

Behavior change

None when the field is false (the default). The value is zero-valued for all existing callers, so the installed middleware behaves exactly as before.

Tests

Added two black-box tests in the canonical provider/openaiprovider/chat_test.go:

  • TestChatMessageInjection_ToolInjectsMessage: builds an agent with AgentConfig.EnableMessageInjection=true and a tool that calls MessageInjectorFromContext(ctx).EnqueueMessages(...); asserts the injected message is forwarded to the provider on the following service round and the final answer is produced. This test fails before the wiring change and passes after.
  • TestChatMessageInjection_DisabledReturnsNilInjector: negative case with the field false, asserting MessageInjectorFromContext returns nil and nothing is injected.

go build ./..., go vet, and go test (incl. -race on the new tests) pass for the changed packages.

Open design questions

  • Scope: This threads the existing harness flag through all five providers for consistency. Should the responses/agui paths be excluded if they are considered out of scope for the initial cut?
  • API shape: EnableMessageInjection sits on agent.Config alongside DisableFuncAutoCall. Is that the desired home, or should message injection be surfaced as part of a broader composable-middleware config (cf. Add composable function-invocation middleware to the tool autocall loop #638)?
  • Follow-ups: Only the injector enable flag is plumbed; other toolautocall.Config knobs (e.g. AllowConcurrentInvocations, MaximumIterationsPerRequest) remain provider-internal. Happy to plumb those in a follow-up if that is the direction.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 23, 2026
@github-actions github-actions Bot added the public-api-change Pull Request changes public APIs label Jul 24, 2026
@github-actions

This comment has been minimized.

The toolautocall harness fully implements Config.EnableMessageInjection
and its MessageInjector loop, but no provider wired the flag: every
provider built toolautocall.Config with only Logger/LogSensitiveData, so
the message-injector loop was unreachable through the normal agent API.

Add EnableMessageInjection to agent.Config beside DisableFuncAutoCall and
pass it into each provider's guarded toolautocall.New literal (openai
chat and responses, anthropic, gemini, agui). The value threads through
the embedded agent.Config on every provider AgentConfig. Behavior is
unchanged when the field is false (the default).
@github-actions

This comment has been minimized.

# Conflicts:
#	provider/openaiprovider/chat_test.go
@github-actions

This comment has been minimized.

@PratikDhanave
PratikDhanave (PratikDhanave) marked this pull request as ready for review August 4, 2026 06:06
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner August 4, 2026 06:06
Copilot AI lite review requested due to automatic review settings August 4, 2026 06:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the existing toolautocall message-injection loop reachable through the normal provider agent constructors by plumbing an EnableMessageInjection flag through agent.Config and into each provider’s toolautocall.Config.

Changes:

  • Added EnableMessageInjection bool to agent.Config so providers can expose message injection via their embedded agent.Config.
  • Threaded EnableMessageInjection into the provider-installed toolautocall.New(toolautocall.Config{...}) middleware across OpenAI (chat + responses), Anthropic, Gemini, and AGUI providers.
  • Added OpenAI chat black-box tests validating injection-enabled behavior and the default disabled behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
agent/agent.go Adds Config.EnableMessageInjection (public surface) and documents intended behavior.
provider/openaiprovider/chat.go Passes EnableMessageInjection into the OpenAI chat agent’s toolautocall middleware config.
provider/openaiprovider/responses.go Passes EnableMessageInjection into the OpenAI responses agent’s toolautocall middleware config.
provider/openaiprovider/chat_test.go Adds end-to-end tests proving injected messages are forwarded on the next provider call (and nil injector when disabled).
provider/anthropicprovider/agent.go Threads EnableMessageInjection into Anthropic provider toolautocall config.
provider/geminiprovider/agent.go Threads EnableMessageInjection into Gemini provider toolautocall config.
provider/aguiprovider/agui.go Threads EnableMessageInjection into AGUI provider toolautocall config.

Comment thread agent/agent.go
Comment on lines +80 to +84
// EnableMessageInjection lets tool implementations enqueue additional messages into the
// automatic function-call loop via the injector returned by
// [github.com/microsoft/agent-framework-go/agent/harness/toolautocall.MessageInjectorFromContext].
// It is threaded into the provider-installed toolautocall middleware and has no effect when
// DisableFuncAutoCall is true.
# Conflicts:
#	provider/openaiprovider/chat_test.go
@github-actions github-actions Bot added area:agent Changes files in the agent area area:provider Changes files in the provider area area:provider/agui Changes files in the provider / agui area area:provider/anthropic Changes files in the provider / anthropic area area:provider/gemini Changes files in the provider / gemini area area:provider/openai Changes files in the provider / openai area size:large At most 300 changed lines across at most 10 files pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added failed-auto-risk Automatic risk classification was inconclusive or failed and removed pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
# Conflicts:
#	provider/openaiprovider/chat_test.go
@github-actions github-actions Bot added the pending-auto-risk Automatic risk classification is in progress label Aug 22, 2026
@github-actions github-actions Bot added risk:medium Contained production impact requiring normal review depth and removed failed-auto-risk Automatic risk classification was inconclusive or failed labels Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

API Consistency Review — PR #652: Plumb EnableMessageInjection through provider AgentConfig

Scope

This PR adds one exported field, EnableMessageInjection bool, to agent.Config and wires it through five provider constructors so callers can enable the already-implemented toolautocall.MessageInjector loop without opting out of provider-managed middleware.

Cross-repo parity mapping

SDK Surface Default Notes
.NET ChatClientAgentOptions.EnableMessageInjection false (opt-in) Adds MessageInjectingChatClient to the pipeline when true
Python MessageInjectionMiddleware always on — hardcoded in _harness/_agent.py, no opt-out "It is a no-op when no messages are queued for the session, so there is no opt-out."
Go (this PR) agent.Config.EnableMessageInjection false (opt-in) Matches .NET semantics

Assessment

The Go PR's opt-in default (false) is aligned with the .NET SDK and is a documented, intentional divergence from Python, which always enables the middleware (declared a zero-cost no-op when no messages are queued). The field name EnableMessageInjection matches the .NET option name exactly.

No parity issues are found. The exported API addition (agent.Config.EnableMessageInjection) correctly exposes an existing internal capability through the canonical config surface, preserving semantic parity with the .NET opt-in model.

The public-api-change label is already present and appropriate — this PR adds an exported field to agent.Config.

Parity approved.

Generated by Go API Consistency Review Agent · sonnet46 · 35.1 AIC · ⌖ 5.06 AIC · ⊞ 6K ·

@github-actions github-actions Bot removed the pending-auto-risk Automatic risk classification is in progress label Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area area:provider/agui Changes files in the provider / agui area area:provider/anthropic Changes files in the provider / anthropic area area:provider/gemini Changes files in the provider / gemini area area:provider/openai Changes files in the provider / openai area area:provider Changes files in the provider area parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs risk:medium Contained production impact requiring normal review depth size:large At most 300 changed lines across at most 10 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants