Skip to content

feat(agent-testing): fill a mock's result with the call's arguments - #1478

Merged
iceljc merged 1 commit into
SciSharp:masterfrom
yuyixg:features/agent-test-mock-args
Nov 4, 2026
Merged

iceljc merged 1 commit into
SciSharp:masterfrom
yuyixg:features/agent-test-mock-args

Conversation

@yuyixg

@yuyixg yuyixg commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Problem

A function that says back a sentence the model passed it (it sets StopCompletion and its result is the turn's reply) could only be mocked with a fixed resultContent. The turn's output was then the case author's own words, so every assertion on it, llmJudge included, tested the case rather than the agent.

Change

  • A mock's resultContent may hold {{args.name}}, filled with that top-level argument of the call it answers (MockResultTemplate). A string argument goes in as it is, any other JSON value as its raw text, and a missing argument or non-object arguments as nothing. A result without placeholders is left untouched.
  • The recorded ObservedToolCall.ResultContent is the filled text, as the agent saw it.

Why now

The RSP phone agent's identify_service now speaks the model's restatement followed by a fixed address check. Its agent-test mocks use {{args.restatement}} Before we get too far, ... with stopCompletion: true, so the restatement the model wrote is what llmJudge scores.

Tests

MockFunctionExecutorTests: placeholders filled from the call's arguments, the observed result matching what the agent saw, non-object or missing arguments filling nothing, and a JSON result with no placeholders left as it is. All AgentTesting unit tests pass (374).

🤖 Generated with Claude Code

A mock's resultContent may now hold {{args.name}}, filled with that top-level
argument of the call it answers. A function that says back a sentence the model
passed it (StopCompletion) could only be mocked with the case author's own
words, so assertions on that turn's output tested the case, not the agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qodo-code-review

qodo-code-review Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Render mock results from tool-call arguments

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Allow mock results to include top-level arguments supplied by the agent's tool call.
• Record the rendered result so observed calls reflect what the agent received.
• Test substitution, missing or invalid arguments, and unchanged results without placeholders.
Diagram

graph TD
  Call["Tool call"] --> Match["Mock matcher"] --> Render["Result renderer"] --> Content["Agent message"]
  Render --> Record["Observed call"]
  Mock["Mock definition"] --> Match
  Mock --> Render
  Call --> Render
Loading
High-Level Assessment

Keep the dedicated, narrowly scoped renderer. A general template engine would add unnecessary capabilities and dependencies for top-level argument substitution; rendering in the executor also ensures the message and observation use the same result.

Files changed (4) +81 / -3

Enhancement (2) +43 / -2
MockFunctionExecutor.csApply rendered results to messages and observations +3/-2

Apply rendered results to messages and observations

• Renders a matched mock's result with the current call's arguments. Writes that same text to message.Content and the observed tool-call record.

src/Plugins/BotSharp.Plugin.AgentTesting/Runtime/MockFunctionExecutor.cs

MockResultTemplate.csAdd top-level argument substitution for mock results +40/-0

Add top-level argument substitution for mock results

• Replaces {{args.name}} placeholders with string values or raw JSON for other value types. Missing properties and non-object or invalid arguments produce empty substitutions; results without placeholders remain unchanged.

src/Plugins/BotSharp.Plugin.AgentTesting/Runtime/MockResultTemplate.cs

Tests (1) +34 / -0
MockFunctionExecutorTests.csCover rendered mock results and fallback behavior +34/-0

Cover rendered mock results and fallback behavior

• Tests substitution through the executor and confirms the observed result matches the message. Also covers missing, invalid, and non-object arguments and an unchanged result without placeholders.

tests/BotSharp.Core.UnitTests/AgentTesting/MockFunctionExecutorTests.cs

Documentation (1) +4 / -1
AgentTestCase.csDocument argument placeholders in mock results +4/-1

Document argument placeholders in mock results

• Documents that ResultContent can reference a tool call's argument using {{args.name}}.

src/Plugins/BotSharp.Plugin.AgentTesting/Models/AgentTestCase.cs

@iceljc
iceljc merged commit c7a12af into SciSharp:master Nov 4, 2026
4 checks passed
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.

2 participants