Repository navigation
Integrate Agent Framework harness into QA bot #17496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jiaqi Zhang (JiaqiZhang-Dev)
wants to merge
15
commits into
main
Choose a base branch
from
jiaqizhang-dev-copilot-harness-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76f31fb
Integrate Agent Framework harness
JiaqiZhang-Dev 6c4cb8d
Fix harness isolation and packaging
JiaqiZhang-Dev 512c3e9
Use hosted Responses protocol 2.0
JiaqiZhang-Dev 679e328
Allow configuring perf evaluation concurrency
JiaqiZhang-Dev 2478917
Upload evaluation inputs as files
JiaqiZhang-Dev 4c8e931
Use valid eval file expiration
JiaqiZhang-Dev 75a459b
Isolate stateless harness sessions
JiaqiZhang-Dev d85e765
Use supported eval file upload options
JiaqiZhang-Dev 8c70936
Fix file-backed eval item shape
JiaqiZhang-Dev be68247
Move evaluation pipeline changes to separate PR
JiaqiZhang-Dev 6e154d3
Merge remote-tracking branch 'origin/main' into jiaqizhang-dev-copilo…
JiaqiZhang-Dev 55ecee6
Merge remote-tracking branch 'origin/main' into jiaqizhang-dev-copilo…
JiaqiZhang-Dev cf9c947
Ignore local harness file memory
JiaqiZhang-Dev 1fa8512
Remove harness file memory ignore
JiaqiZhang-Dev f73a41b
Optimize QA bot harness configuration
JiaqiZhang-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tools/sdk-ai-bots/azure-sdk-qa-bot-agent/middleware/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Agent middleware.""" |
68 changes: 68 additions & 0 deletions
68
tools/sdk-ai-bots/azure-sdk-qa-bot-agent/middleware/tool_output_security.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """Tool-output security middleware (prompt-injection defence). | ||
|
|
||
| Spotlights untrusted tool output as *data, not instructions* by wrapping it in | ||
| a labelled, JSON-escaped delimiter. Native ``@tool`` functions and trusted | ||
| harness tools are left unchanged. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from collections.abc import Awaitable, Callable | ||
| from copy import copy | ||
|
|
||
| from agent_framework import Content, FunctionInvocationContext, FunctionMiddleware | ||
|
|
||
| from tools import TOOL_REGISTRY | ||
|
|
||
| _SPOTLIGHT_OPEN = "<untrusted_tool_output>" | ||
| _SPOTLIGHT_CLOSE = "</untrusted_tool_output>" | ||
| _TRUSTED_HARNESS_TOOLS = { | ||
| "load_skill", | ||
| "read_skill_resource", | ||
| } | ||
|
|
||
|
|
||
| def spotlight(text: str) -> str: | ||
| """Wrap opaque tool output as a labelled, JSON-escaped untrusted block.""" | ||
| escaped = json.dumps(text, ensure_ascii=False).replace("/", "\\/") | ||
| return f"{_SPOTLIGHT_OPEN}\n{escaped}\n{_SPOTLIGHT_CLOSE}" | ||
|
|
||
|
|
||
| class ToolOutputSecurityMiddleware(FunctionMiddleware): | ||
| """Spotlight opaque tool results as untrusted data.""" | ||
|
|
||
| async def process( | ||
| self, | ||
| context: FunctionInvocationContext, | ||
| call_next: Callable[[], Awaitable[None]], | ||
| ) -> None: | ||
| await call_next() | ||
|
|
||
| if ( | ||
| context.function.name in TOOL_REGISTRY | ||
| or context.function.name in _TRUSTED_HARNESS_TOOLS | ||
| ): | ||
| return | ||
|
|
||
| result = context.result | ||
| if isinstance(result, str) and result: | ||
| context.result = spotlight(result) | ||
| elif isinstance(result, list): | ||
| protected_result = [] | ||
| for item in result: | ||
| if isinstance(item, Content) and item.type == "text" and item.text: | ||
| protected_item = copy(item) | ||
| protected_item.text = spotlight(item.text) | ||
| protected_result.append(protected_item) | ||
| elif isinstance(item, Content): | ||
| protected_result.append(item) | ||
| else: | ||
| protected_result.append( | ||
| spotlight(json.dumps(item, ensure_ascii=False, default=str)) | ||
| ) | ||
| context.result = protected_result | ||
| elif isinstance(result, dict): | ||
| context.result = spotlight( | ||
| json.dumps(result, ensure_ascii=False, default=str) | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.