mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
a5b36dc379
* Python: Add factory pattern to concurrent orchestration builder (#2738) * Add factory pattern to concurrent orchestration builder * Update readme * Address AI comments * Fix unit tests * Fix import * Prevent multiple calls to set participants or factories * Add comments * Mitigate warnings * Fix mypy * Address comments * Address Copilot comments * Fix tests * Python: fix: GroupChat ManagerSelectionResponse JSON Schema for OpenAI Structured Outpu… (#2750) * fix: ManagerSelectionResponse JSON Schema for OpenAI Structured Output Strict Mode * refactor: install pre-commit then commit again * Capture file IDs from code interpreter in streaming responses (#2741) * .NET: [BREAKING] Prevent nulls in AIAgent property (#2719) * prevent nulls in AIAgent property * address feedback * code ql sm04598 (#2723) Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> * .NET: Add Conversation State Sample (Step05) (#2697) * Initial plan * Add Agent_OpenAI_Step05_Conversation sample for conversation state management Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> * Update Program.cs comment to accurately describe the sample Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> * Update the code to use the ConversationClient more in line with the samples in OpenAI * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Changing sample to use ChatClientAgent and conversationId in GetNewThread --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Bump AWSSDK.Extensions.Bedrock.MEAI from 4.0.4.7 to 4.0.4.11 (#2777) --- updated-dependencies: - dependency-name: AWSSDK.Extensions.Bedrock.MEAI dependency-version: 4.0.4.11 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Azure.Identity from 1.17.0 to 1.17.1 (#2780) --- updated-dependencies: - dependency-name: Azure.Identity dependency-version: 1.17.1 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.Identity dependency-version: 1.17.1 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.Identity dependency-version: 1.17.1 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.Identity dependency-version: 1.17.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Azure.AI.AgentServer.AgentFramework from 1.0.0-beta.4 to 1.0.0-beta.5 (#2778) --- updated-dependencies: - dependency-name: Azure.AI.AgentServer.AgentFramework dependency-version: 1.0.0-beta.5 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.AI.AgentServer.AgentFramework dependency-version: 1.0.0-beta.5 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.AI.AgentServer.AgentFramework dependency-version: 1.0.0-beta.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Python: added more complete parsing for mcp tool arguments (#2756) * added more complete parsing for mcp tool arguments * fixed mypy * added nonlocal model counter, and some fixes * fixes in naming logic * extracted json parsing function, added parametrized test and checked coverage * Python: Updated package versions (#2784) * Updated package versions * Small fix * Bump actions/checkout from 5 to 6 (#2404) Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> * .NET: adds support for labels in edges, fixes rendering of labels in dot a… (#1507) * adds support for labels in edges, fixes rendering of labels in dot and mermaid, adds rendering of labels in edges * Update dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * escaping edge labels, adding tests for labels containing strange characters that would break the diagram and enabling the previous signature so the API has backwards compatibility. * Unify label in EdgeData * Edge API adjustments, removed useless "sanitizer" * fixed test --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jacob Alber <jaalber@microsoft.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> * Python: Added custom args and thread object to ai_function kwargs (#2769) * Added an example of using kwargs in ai_function * Added thread object to ai_function kwargs * Updated docs * Small fix * Added thread parameter filtering * Fix WorkflowAgent to include thread convo history. Enable checkpointing. (#2774) * Update OpenAIResponses.yaml to match AgentSchema (#2598) 1. Update `connection` child types -- `kind: ApiKey` to `kind: key` otherwise schema will fail: https://microsoft.github.io/AgentSchema/reference/apikeyconnection/ 2. Update `outputSchema`'s `PropertySchema` to be `kind` instead of `type` otherwise schema will fail: https://microsoft.github.io/AgentSchema/reference/propertyschema/ * Python: Remove warnings from workflow builder on not using factories (#2808) * Revert concurrent * Fix comments * Python: Filter framework kwargs from MCP tool invocations (#2870) * Filter framework kwargs from MCP tool invocations * Fixes * Python: Fix WorkflowAgent to emit yield_output as agent response (#2866) * Fix WorkflowAgent to emit yield_output as agent response * use raw_representation * Raw representation handling * Python: Use agent description in HandoffBuilder auto-generated tools (#2713) (#2714) ## Summary Enhanced `HandoffBuilder._apply_auto_tools` to use the target agent's description when creating handoff tools, providing more informative tool descriptions for LLMs. ## Changes - Modified `_apply_auto_tools` to extract `description` from `AgentExecutor._agent` when available - Updated iteration to use `.items()` for more efficient dict traversal - Handoff tools now use agent descriptions instead of generic placeholders ## Example Before: "Handoff to the refund_agent agent." After: "You handle refund requests. Ask for order details and process refunds." ## Testing - All handoff tests pass (20/20) - No breaking changes to existing API Fixes #2713 Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> * Python: [BREAKING] Observability updates (#2782) * fixes Python: Add env_file_path parameter to setup_observability() similar to AzureOpenAIChatClient Fixes #2186 * WIP on updates using configure_azure_monitor * improved setup and clarity * fixed root .env.example * revert changes * updated files * updated sample * updated zero code * test fixes and fixed links * fix devui * removed planning docs * added enable method and updated readme and samples * clarified docstring * add return annotation * updated naming * update capatilized version * updated readme and some fixes * updated decorator name inline with the rest * feedback from comments addressed * Python: Fix middleware terminate flag to exit function calling loop immediately (#2868) * Fix middleware terminate flag to exit function calling loop immediately * Eliminating duck typing * Improve function exec result handling * Fix race condition * Fix mypy issues * Python: Fix context duplication in handoff workflows when restoring from checkpoint (#2867) * Fix context duplication in handoff workflows when restoring from checkpoint * Address Copilot PR review * .NET: Update to latest Azure.AI.*, OpenAI, and M.E.AI* (#2850) * Update to latest Azure.AI.*, OpenAI, and M.E.AI* Absorb breaking changes in Responses surface area * Update dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/Utilities/ChatClientExtensions.cs * Update dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/Utilities/ChatClientExtensions.cs * Update dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/Utilities/ChatClientExtensions.cs * Update dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step04_CreateFromOpenAIResponseClient/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Using patch to remove the model is necessary, updated the response client to actually use the the ForAgent --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> * Bump actions/download-artifact from 6 to 7 (#2862) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6 to 7. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/cache from 4 to 5 (#2861) Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/cache dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/upload-artifact from 5 to 6 (#2860) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Python : Ollama Connector for Agent Framework (#1104) * Initial Commit for Olama Connector * Added Olama Sample * Add Sample & Fixed Open Telemetry * Fixed Spelling from Olama to Ollama * remove"opentelemetry-semantic-conventions-ai ~=0.4.13" since its handled in a different pr * Added Tool Calling * Finalizing test cases * Adjust samples to be more reliable * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/pyproject.toml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/tests/test_ollama_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improved Docstrings & Sample * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> * Integrate PR Feedback - Divided Streaming and Non-Streaming into independent Methods - Catch Ollama Validation Error - Add OTEL Provider Name - Checked Ollama Messages - Add Usage Statistics * Revert setting, so it can be none * Validate Message formatting between AF and Ollama * Catch Ollama Error and raise a ServiceResponse Error * Fix mypy error * remove .vscode comma * Add Reasoning support & adjust to new structure * Add Ollama Multimodality and Reasoning * Add test cases for reasoning * Add Tests for Error Handling in Ollama Client * Update python/samples/getting_started/multimodal_input/ollama_chat_multimodal.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Integrated Copilot Feedback * Implement first PR Feedback * Adjust Readme files for examples * Adjust argument passing via additional chat options * Implemented PR Feedback * Removing Ollama Package from Core and moving samples * Fix Link & Adding Samples to Main Sample Readme * Fixing Links in Readme * Moved Multimodal and Chat Example * Fixed Link in ChatClient to Ollama * Fix AgentFramework Links in Ollama Project * Fix observability breaking change --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> * Skip failing IT (#2904) * .NET: Cosmos DB UT Fast Skip (For Non-Configured Local envs) (#2906) * Cosmos DB UT Fast Skip (Non-Configured Local envs) + Long running UT skip in pipeline when no CosmosDB changes happened * Force a CosmosDB source code change to trigger the pipeline * Address possible string boolean mismatch * Add debug * Enabling emulator always when running IT * .NET: Add TTLs to durable agent sessions (#2679) * .NET: Add TTLs to durable agent sessions * Remove unnecessary async * PR feedback: clarify UTC * PR feedback: limit minimum signal delay to <= 5 minutes * PR feedback: Fix TTL disablement * Linter: use auto-property * Fix build break from OpenAI SDK change * Updated CHANGELOG.md * PR feedback * Reduce default TTL to 14 days to work around DTS bug * Python: Update Mem0Provider to use v2 search API `filters` parameter (#2766) * short fix to move id parameters to filters object * added tests * small fix * mem0 dependency update * Updated package versions (#2913) * .NET: Switch to new "Run" method name. (#2843) * Switch to new "RunAgent" method name. * Try to disable false positive naming warning. * Add comment about disabled warnings. * Rename `RunAgent` to just `Run`. * Update CHANGELOG. * Python: Switch to new "run" method name. (#2890) * Switch to `run` method. * Add support for deprecated `run_agent`. * Fix entity method name. * Fix method name and improve tests. * Update comment. * Update Python CHANGELOG. * [BREAKING] Python: Add factory pattern to handoff orchestration builder (#2844) * WIP: Factory pattern to handoff * Add factory pattern to concurrent orchestration builder; Next: tests and sample verification * Add tests and improve comments * Fix mypy * Simplify handoff_simple.py * Simplify handoff_autonoumous.py and bug fix * Update readme * Address Copilot comments * Python: Flow custom kwargs to agents via Workflow SharedState (#2894) * Flow custom kwargs to agents via SharedState * Address Copilot feedback * Improve sample typing * Fix test * Fix Pydantic error when using Literal type for tool params (#2893) * Updated Ollama package version (#2920) * Python: Azure AI Agent with Bing Grounding Citations Sample (#2892) * bing grounding sample with citations * small fix * fix * .NET: Make DelegatingAIAgent abstract (#2797) * Initial plan * Make DelegatingAIAgent abstract Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Added additional arguments for Azure AI agent (#2922) * Python: Correction of MCP image type conversion in _mcp.py (#2901) * Correction of MCP image type conversion in _mcp.py * Added a new overload to the init function of the DataContent() type of the Agent Framework, edited the test case to correctly test the usage of the data and uri fields while using DataContent() * Fixed tests related to the changes of the DataContent type, added testing for both string and byte representations * Pass kwargs into subworkflows (#2923) * Python: Move ollama samples to samples getting started dir (#2921) * Move ollama samples to samples getting started dir * Address feedback * Python: fix: correct BadRequestError when using Pydantic model in response_fo… (#1843) * fix: correct BadRequestError when using Pydantic model in response_format * Fix lint --------- Co-authored-by: Evan Mattson <evan.mattson@microsoft.com> * .NET: [Breaking] Delete display name property (#2758) * delete the AIAgent.DisplayName property * use agent name as a first value for activity display name * Update dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Python: cleanup and refactoring of chat clients (#2937) * refactoring and unifying naming schemes of internal methods of chat clients * set tool_choice to auto * fix for mypy * added note on naming and fix #2951 * fix responses * fixes in azure ai agents client * Python: Workflow add option to visualize internal executors (#2917) * Workflow add option to visualize internal executors * Address Copilot comments * Python: Fixes Run ID and Thread ID casing to align with AG-UI Typescript SDK (#2948) * added camelCase input to run id and thread id aligning with @ag-ui/core * fixed per copilot suggestions * Python: Add workflow cancellation sample (#2732) * Add workflow cancellation sample Add sample demonstrating how to cancel a running workflow using asyncio tasks. Shows both cancellation mid-execution and normal completion paths. Useful for implementing timeouts, graceful shutdown, or A2A executors. * update docstring * .NET: Update Anthropic package to version 12.0.0 (#2914) * Initial plan * Update Anthropic package to version 12.0.0 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Python: Add Azure Managed Redis Support with Credential Provider (#2887) * azure redis support * small fixes * azure managed redis sample * fixes * Bump CommunityToolkit.Aspire.OllamaSharp from 13.0.0-beta.440 to 13.0.0 (#2856) --- updated-dependencies: - dependency-name: CommunityToolkit.Aspire.OllamaSharp dependency-version: 13.0.0 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump AWSSDK.Extensions.Bedrock.MEAI from 4.0.4.11 to 4.0.5 (#2853) --- updated-dependencies: - dependency-name: AWSSDK.Extensions.Bedrock.MEAI dependency-version: 4.0.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> * Bump Azure.AI.AgentServer.AgentFramework from 1.0.0-beta.4 to 1.0.0-beta.5 (#2854) --- updated-dependencies: - dependency-name: Azure.AI.AgentServer.AgentFramework dependency-version: 1.0.0-beta.5 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Azure.AI.AgentServer.AgentFramework dependency-version: 1.0.0-beta.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> * Python: Fix WorkflowAgent event handling and kwargs forwarding (#2946) * Fix kwargs propagation through workflow.as_agent() * Fix WorkflowAgent to respect AgentExecutor output_response setting * .NET: Use GrpcEntityRunner instead of TaskEntityDispatcher (#2759) * Use GrpcEntityRunner instead of TaskEntityDispatcher * Pin to Durable worker 1.11.0 * Set the invocation result * Update all Durable packages * Update changelog, rename dispatcher to encondedEntityRequest * Python: Bump Py version to 1.0.0b251218 for a release. Update CHANGELOG (#2968) * Bump Py version to 1.0.0b251218 for a release. Update CHANGELOG * update lock * Fix formatting * Fix ChatKit typing * Python: Introducing Foundry Local Chat Clients (#2915) * redo foundry local chat client * fix mypy and spelling * better docstring, updated sample * fixed tests and added tests * small sample update * Updated package versions (#2978) * Python: Added GitHub MCP sample with PAT (#2967) * added github mcp sample with PAT * addressed copilot fixes * env fix * Python: Preserve reasoning blocks with OpenRouter (#2950) * Preserve reasoning blocks with OpenRouter * Put encrypted reasoning in TextReasoningContent * Remove unneccessary change * Fix docs * Support streaming * Fix handling None in TextReasoningContent.text * Python: Added response.created and response.in_progress event process to OpenAIBaseResponseClient (#2975) * added response.created and response.in_progress to include response.id * better doc string * added tests for the new streaming event types * Python: Introducing support for Bedrock-hosted models (Anthropic, Cohere, etc.) (#2610) * Pushing the bedrock related changes to the new branch after addressing the review comments * 2524 Addressed the second round review comments * 2524 Addressed few more minor comments on the PR * resolving the merge conflict * 2524 resolved the uv.lock conflicts * 2524 addressed more comments * 2524 removed the print statement to fix the checks failure * 2524 resolved the CI failure issues * 2524 fixing the CI breaks * 2524 Addressed the review comment * 2524 resolved conflict --------- Co-authored-by: Sunil Dutta <sunil.dutta@penske.com> Co-authored-by: budgetboardingai <apurva.sharma31@gmail.com> * .NET: [Durable Agents] Reliable streaming sample (#2942) * .NET: [Durable Agents] Reliable streaming sample * Add automated validation for new sample * Address Copilot PR feedback * Fix typo in README.md about agent definitions (#2634) * Fix typo in README.md about agent definitions * Update agent-samples/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Python: latency improvements (#3014) * latency improvements * fixed mypy, added coding standards and instructions * slight logic improvement * Python: Updated package versions (#3024) * Updated package versions * Updated changelog * Python: add powerfx safe mode (#3028) * add powerfx safe mode * improved docstring and aligned env_file loading * ensured test uses reset * .NET: [Breaking] Introduce RunCoreAsync/RunCoreStreamingAsync delegation pattern in AIAgent (#2749) * Initial plan * Refactor AIAgent: Make RunAsync and RunStreamingAsync non-abstract, add RunCoreAsync and RunCoreStreamingAsync Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Fix infinite recursion in test implementations Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Make RunAsync and RunStreamingAsync non-virtual as requested Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Fix DelegatingAIAgent subclasses to use RunCoreAsync/RunCoreStreamingAsync Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Fix XML documentation references in AnonymousDelegatingAIAgent Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Restore <see cref> tags with proper qualified signatures in AnonymousDelegatingAIAgent Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Rollback unnecessary XML documentation changes in AnonymousDelegatingAIAgent Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Remove pragma and update crefs to RunCoreAsync/RunCoreStreamingAsync Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * Fix EntityAgentWrapper to call base.RunCoreAsync/RunCoreStreamingAsync Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> * fix compilation issues * fix compilatio issue * fix tests * fix unit tests * fix unit test --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Co-authored-by: SergeyMenshykh <sergemenshikh@gmail.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> * Remove from feature branch * Remove ollama changes --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Tao Chen <taochen@microsoft.com> Co-authored-by: Kurt <65111699+q33566@users.noreply.github.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Co-authored-by: Korolev Dmitry <deagle.gross@gmail.com> Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> Co-authored-by: Jose Luis Latorre Millas <joslat@gmail.com> Co-authored-by: Jacob Alber <jaalber@microsoft.com> Co-authored-by: Richard Ortega <richardjortega@gmail.com> Co-authored-by: 刘邦学AI <lbbniu@gmail.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Nico Möller <nkm-moeller@mail.de> Co-authored-by: Chris Gillum <cgillum@microsoft.com> Co-authored-by: Giles Odigwe <79032838+giles17@users.noreply.github.com> Co-authored-by: Phillip Hoff <phillip.hoff@gmail.com> Co-authored-by: Ege Ozan Özyedek <36128615+egeozanozyedek@users.noreply.github.com> Co-authored-by: samueljohnsiby <66901393+samueljohnsiby@users.noreply.github.com> Co-authored-by: Evan Mattson <evan.mattson@microsoft.com> Co-authored-by: Hao Luo <338265+howlowck@users.noreply.github.com> Co-authored-by: Victor Dibia <chuvidi2003@gmail.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Jacob Viau <javia@microsoft.com> Co-authored-by: SuperKenVery <39673849+SuperKenVery@users.noreply.github.com> Co-authored-by: Sunil Dutta <dutta.2003@gmail.com> Co-authored-by: Sunil Dutta <sunil.dutta@penske.com> Co-authored-by: budgetboardingai <apurva.sharma31@gmail.com> Co-authored-by: Syrine Chelly <62653967+SyChell@users.noreply.github.com> Co-authored-by: SergeyMenshykh <sergemenshikh@gmail.com>
1109 lines
38 KiB
Python
1109 lines
38 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
"""Tests for MAML model classes."""
|
|
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from agent_framework_declarative._models import (
|
|
AgentDefinition,
|
|
AgentManifest,
|
|
AnonymousConnection,
|
|
ApiKeyConnection,
|
|
ArrayProperty,
|
|
Binding,
|
|
CodeInterpreterTool,
|
|
Connection,
|
|
CustomTool,
|
|
EnvironmentVariable,
|
|
FileSearchTool,
|
|
Format,
|
|
FunctionTool,
|
|
McpServerApprovalMode,
|
|
McpServerToolAlwaysRequireApprovalMode,
|
|
McpServerToolNeverRequireApprovalMode,
|
|
McpServerToolSpecifyApprovalMode,
|
|
McpTool,
|
|
Model,
|
|
ModelOptions,
|
|
ModelResource,
|
|
ObjectProperty,
|
|
OpenApiTool,
|
|
Parser,
|
|
PromptAgent,
|
|
Property,
|
|
PropertySchema,
|
|
ProtocolVersionRecord,
|
|
ReferenceConnection,
|
|
RemoteConnection,
|
|
Resource,
|
|
Template,
|
|
ToolResource,
|
|
WebSearchTool,
|
|
_safe_mode_context,
|
|
_try_powerfx_eval,
|
|
)
|
|
|
|
pytestmark = pytest.mark.skipif(sys.version_info >= (3, 14), reason="Skipping on Python 3.14+")
|
|
|
|
|
|
class TestBinding:
|
|
"""Tests for Binding class."""
|
|
|
|
def test_binding_creation(self):
|
|
binding = Binding(name="arg1", input="value1")
|
|
assert binding.name == "arg1"
|
|
assert binding.input == "value1"
|
|
|
|
def test_binding_from_dict(self):
|
|
data = {"name": "arg1", "input": "value1"}
|
|
binding = Binding.from_dict(data)
|
|
assert binding.name == "arg1"
|
|
assert binding.input == "value1"
|
|
|
|
def test_binding_to_dict(self):
|
|
binding = Binding(name="arg1", input="value1")
|
|
result = binding.to_dict()
|
|
assert result["name"] == "arg1"
|
|
assert result["input"] == "value1"
|
|
|
|
|
|
class TestProperty:
|
|
"""Tests for Property class."""
|
|
|
|
def test_property_creation(self):
|
|
prop = Property(
|
|
name="test_prop",
|
|
kind="string",
|
|
description="A test property",
|
|
required=True,
|
|
default="default_value",
|
|
example="example_value",
|
|
enum=["val1", "val2"],
|
|
)
|
|
assert prop.name == "test_prop"
|
|
assert prop.kind == "string"
|
|
assert prop.description == "A test property"
|
|
assert prop.required is True
|
|
assert prop.default == "default_value"
|
|
assert prop.example == "example_value"
|
|
assert prop.enum == ["val1", "val2"]
|
|
|
|
def test_property_from_dict(self):
|
|
data = {
|
|
"name": "test_prop",
|
|
"kind": "string",
|
|
"description": "A test property",
|
|
"required": True,
|
|
}
|
|
prop = Property.from_dict(data)
|
|
assert prop.name == "test_prop"
|
|
assert prop.kind == "string"
|
|
assert prop.description == "A test property"
|
|
assert prop.required is True
|
|
|
|
|
|
class TestArrayProperty:
|
|
"""Tests for ArrayProperty class."""
|
|
|
|
def test_array_property_creation(self):
|
|
items = Property(name="item", kind="string")
|
|
array_prop = ArrayProperty(name="test_array", kind="array", items=items, required=True)
|
|
assert array_prop.name == "test_array"
|
|
assert array_prop.kind == "array"
|
|
assert array_prop.items.name == "item"
|
|
assert array_prop.required is True
|
|
|
|
def test_array_property_from_dict(self):
|
|
data = {
|
|
"name": "test_array",
|
|
"kind": "array",
|
|
"items": {"name": "item", "kind": "string"},
|
|
"required": True,
|
|
}
|
|
array_prop = ArrayProperty.from_dict(data)
|
|
assert array_prop.name == "test_array"
|
|
assert array_prop.kind == "array"
|
|
assert isinstance(array_prop.items, Property)
|
|
assert array_prop.items.name == "item"
|
|
|
|
|
|
class TestObjectProperty:
|
|
"""Tests for ObjectProperty class."""
|
|
|
|
def test_object_property_creation(self):
|
|
props = [
|
|
Property(name="prop1", kind="string"),
|
|
Property(name="prop2", kind="integer"),
|
|
]
|
|
obj_prop = ObjectProperty(name="test_object", kind="object", properties=props, required=True)
|
|
assert obj_prop.name == "test_object"
|
|
assert obj_prop.kind == "object"
|
|
assert len(obj_prop.properties) == 2
|
|
assert obj_prop.properties[0].name == "prop1"
|
|
|
|
def test_object_property_from_dict(self):
|
|
data = {
|
|
"name": "test_object",
|
|
"kind": "object",
|
|
"properties": [
|
|
{"name": "prop1", "kind": "string"},
|
|
{"name": "prop2", "kind": "integer"},
|
|
],
|
|
"required": True,
|
|
}
|
|
obj_prop = ObjectProperty.from_dict(data)
|
|
assert obj_prop.name == "test_object"
|
|
assert obj_prop.kind == "object"
|
|
assert len(obj_prop.properties) == 2
|
|
assert all(isinstance(p, Property) for p in obj_prop.properties)
|
|
|
|
def test_object_property_with_dict_properties(self):
|
|
"""Test ObjectProperty with dict format for properties (MAML YAML dict syntax)."""
|
|
data = {
|
|
"name": "person",
|
|
"kind": "object",
|
|
"properties": {
|
|
"name": {"kind": "string", "required": True},
|
|
"email": {"kind": "string"},
|
|
"age": {"kind": "integer"},
|
|
},
|
|
}
|
|
obj_prop = ObjectProperty.from_dict(data)
|
|
assert obj_prop.name == "person"
|
|
assert obj_prop.kind == "object"
|
|
assert len(obj_prop.properties) == 3
|
|
|
|
# Check that all properties were converted correctly
|
|
prop_names = {p.name for p in obj_prop.properties}
|
|
assert prop_names == {"name", "email", "age"}
|
|
|
|
# Check specific property
|
|
name_prop = next(p for p in obj_prop.properties if p.name == "name")
|
|
assert name_prop.kind == "string"
|
|
assert name_prop.required is True
|
|
|
|
|
|
class TestPropertySchema:
|
|
"""Tests for PropertySchema class."""
|
|
|
|
def test_property_schema_creation(self):
|
|
props = [Property(name="prop1", kind="string")]
|
|
schema = PropertySchema(properties=props, strict=True)
|
|
assert schema.strict is True
|
|
assert len(schema.properties) == 1
|
|
|
|
def test_property_schema_from_dict(self):
|
|
data = {
|
|
"strict": False,
|
|
"properties": [{"name": "prop1", "kind": "string"}],
|
|
}
|
|
schema = PropertySchema.from_dict(data)
|
|
assert schema.strict is False
|
|
assert len(schema.properties) == 1
|
|
# Properties are properly converted to Property instances
|
|
assert isinstance(schema.properties[0], Property)
|
|
assert schema.properties[0].name == "prop1"
|
|
assert schema.properties[0].kind == "string"
|
|
|
|
def test_property_schema_with_dict_properties(self):
|
|
"""Test PropertySchema with dict format for properties (MAML YAML dict syntax)."""
|
|
data = {
|
|
"strict": True,
|
|
"properties": {
|
|
"firstName": {"kind": "string", "description": "First name"},
|
|
"lastName": {"kind": "string", "description": "Last name"},
|
|
"age": {"kind": "integer", "required": True},
|
|
},
|
|
}
|
|
schema = PropertySchema.from_dict(data)
|
|
assert schema.strict is True
|
|
assert len(schema.properties) == 3
|
|
|
|
# Check that all properties were converted correctly
|
|
prop_names = {p.name for p in schema.properties}
|
|
assert prop_names == {"firstName", "lastName", "age"}
|
|
|
|
# Check specific property details
|
|
age_prop = next(p for p in schema.properties if p.name == "age")
|
|
assert age_prop.kind == "integer"
|
|
assert age_prop.required is True
|
|
|
|
|
|
class TestConnection:
|
|
"""Tests for Connection base class."""
|
|
|
|
def test_connection_creation(self):
|
|
conn = Connection(kind="base")
|
|
assert conn.kind == "base"
|
|
|
|
def test_connection_from_dict(self):
|
|
data = {"kind": "base"}
|
|
conn = Connection.from_dict(data)
|
|
assert conn.kind == "base"
|
|
|
|
|
|
class TestReferenceConnection:
|
|
"""Tests for ReferenceConnection class."""
|
|
|
|
def test_reference_connection_creation(self):
|
|
conn = ReferenceConnection(name="my-connection", target="target-connection")
|
|
assert conn.kind == "reference"
|
|
assert conn.name == "my-connection"
|
|
assert conn.target == "target-connection"
|
|
|
|
def test_reference_connection_from_dict(self):
|
|
data = {"kind": "reference", "name": "my-connection", "target": "target-connection"}
|
|
conn = ReferenceConnection.from_dict(data)
|
|
assert conn.kind == "reference"
|
|
assert conn.name == "my-connection"
|
|
assert conn.target == "target-connection"
|
|
|
|
|
|
class TestRemoteConnection:
|
|
"""Tests for RemoteConnection class."""
|
|
|
|
def test_remote_connection_creation(self):
|
|
conn = RemoteConnection(name="my-remote", endpoint="https://api.example.com")
|
|
assert conn.kind == "remote"
|
|
assert conn.endpoint == "https://api.example.com"
|
|
|
|
def test_remote_connection_from_dict(self):
|
|
data = {"kind": "remote", "endpoint": "https://api.example.com"}
|
|
conn = RemoteConnection.from_dict(data)
|
|
assert conn.kind == "remote"
|
|
assert conn.endpoint == "https://api.example.com"
|
|
|
|
|
|
class TestApiKeyConnection:
|
|
"""Tests for ApiKeyConnection class."""
|
|
|
|
def test_api_key_connection_creation(self):
|
|
conn = ApiKeyConnection(apiKey="secret-key", endpoint="https://api.example.com")
|
|
assert conn.kind == "key"
|
|
assert conn.apiKey == "secret-key"
|
|
assert conn.endpoint == "https://api.example.com"
|
|
|
|
def test_api_key_connection_from_dict(self):
|
|
data = {"kind": "key", "apiKey": "secret-key", "endpoint": "https://api.example.com"}
|
|
conn = ApiKeyConnection.from_dict(data)
|
|
assert conn.kind == "key"
|
|
assert conn.apiKey == "secret-key"
|
|
|
|
|
|
class TestAnonymousConnection:
|
|
"""Tests for AnonymousConnection class."""
|
|
|
|
def test_anonymous_connection_creation(self):
|
|
conn = AnonymousConnection(endpoint="https://api.example.com")
|
|
assert conn.kind == "anonymous"
|
|
assert conn.endpoint == "https://api.example.com"
|
|
|
|
def test_anonymous_connection_from_dict(self):
|
|
data = {"kind": "anonymous", "endpoint": "https://api.example.com"}
|
|
conn = AnonymousConnection.from_dict(data)
|
|
assert conn.kind == "anonymous"
|
|
assert conn.endpoint == "https://api.example.com"
|
|
|
|
|
|
class TestModelOptions:
|
|
"""Tests for ModelOptions class."""
|
|
|
|
def test_model_options_creation(self):
|
|
options = ModelOptions(temperature=0.7, maxOutputTokens=1000, topP=0.9)
|
|
assert options.temperature == 0.7
|
|
assert options.maxOutputTokens == 1000
|
|
assert options.topP == 0.9
|
|
|
|
def test_model_options_from_dict(self):
|
|
data = {"temperature": 0.7, "maxOutputTokens": 1000, "topP": 0.9}
|
|
options = ModelOptions.from_dict(data)
|
|
assert options.temperature == 0.7
|
|
assert options.maxOutputTokens == 1000
|
|
assert options.topP == 0.9
|
|
|
|
|
|
class TestModel:
|
|
"""Tests for Model class."""
|
|
|
|
def test_model_creation(self):
|
|
model = Model(id="gpt-4", provider="openai")
|
|
assert model.id == "gpt-4"
|
|
assert model.provider == "openai"
|
|
|
|
def test_model_from_dict(self):
|
|
data = {"id": "gpt-4", "provider": "openai"}
|
|
model = Model.from_dict(data)
|
|
assert model.id == "gpt-4"
|
|
assert model.provider == "openai"
|
|
|
|
def test_model_with_connection(self):
|
|
data = {
|
|
"id": "gpt-4",
|
|
"connection": {"kind": "reference", "name": "my-connection"},
|
|
}
|
|
model = Model.from_dict(data)
|
|
assert model.id == "gpt-4"
|
|
assert model.connection.kind == "reference"
|
|
|
|
|
|
class TestFormat:
|
|
"""Tests for Format class."""
|
|
|
|
def test_format_creation(self):
|
|
fmt = Format(kind="json", strict=True, options={"type": "object"})
|
|
assert fmt.kind == "json"
|
|
assert fmt.strict is True
|
|
assert fmt.options == {"type": "object"}
|
|
|
|
def test_format_from_dict(self):
|
|
data = {"kind": "json", "strict": False, "options": {"type": "object"}}
|
|
fmt = Format.from_dict(data)
|
|
assert fmt.kind == "json"
|
|
assert fmt.strict is False
|
|
|
|
|
|
class TestParser:
|
|
"""Tests for Parser class."""
|
|
|
|
def test_parser_creation(self):
|
|
parser = Parser(kind="json", options={"strict": True})
|
|
assert parser.kind == "json"
|
|
assert parser.options == {"strict": True}
|
|
|
|
def test_parser_from_dict(self):
|
|
data = {"kind": "json", "options": {"strict": True}}
|
|
parser = Parser.from_dict(data)
|
|
assert parser.kind == "json"
|
|
assert parser.options == {"strict": True}
|
|
|
|
|
|
class TestTemplate:
|
|
"""Tests for Template class."""
|
|
|
|
def test_template_creation(self):
|
|
template = Template(
|
|
format=Format(kind="text"),
|
|
parser=Parser(kind="text"),
|
|
)
|
|
assert isinstance(template.format, Format)
|
|
assert isinstance(template.parser, Parser)
|
|
|
|
def test_template_from_dict(self):
|
|
data = {
|
|
"format": {"kind": "text"},
|
|
"parser": {"kind": "text"},
|
|
}
|
|
template = Template.from_dict(data)
|
|
assert isinstance(template.format, Format)
|
|
assert isinstance(template.parser, Parser)
|
|
|
|
|
|
class TestAgentDefinition:
|
|
"""Tests for AgentDefinition class."""
|
|
|
|
def test_agent_definition_creation(self):
|
|
agent = AgentDefinition(
|
|
name="test-agent",
|
|
description="A test agent",
|
|
)
|
|
assert agent.name == "test-agent"
|
|
assert agent.description == "A test agent"
|
|
|
|
def test_agent_definition_from_dict(self):
|
|
data = {
|
|
"name": "test-agent",
|
|
"description": "A test agent",
|
|
}
|
|
agent = AgentDefinition.from_dict(data)
|
|
assert agent.name == "test-agent"
|
|
assert agent.description == "A test agent"
|
|
|
|
|
|
class TestFunctionTool:
|
|
"""Tests for FunctionTool class."""
|
|
|
|
def test_function_tool_creation(self):
|
|
tool = FunctionTool(
|
|
name="my_function",
|
|
description="A test function",
|
|
kind="function",
|
|
)
|
|
assert tool.name == "my_function"
|
|
assert tool.kind == "function"
|
|
|
|
def test_function_tool_from_dict(self):
|
|
data = {
|
|
"name": "my_function",
|
|
"description": "A test function",
|
|
"kind": "function",
|
|
"strict": False,
|
|
}
|
|
tool = FunctionTool.from_dict(data)
|
|
assert tool.name == "my_function"
|
|
assert tool.kind == "function"
|
|
|
|
def test_function_tool_with_dict_bindings(self):
|
|
"""Test FunctionTool with dict format for bindings (MAML YAML dict syntax)."""
|
|
data = {
|
|
"name": "calculate",
|
|
"kind": "function",
|
|
"description": "Calculate something",
|
|
"bindings": {
|
|
"x": "input.x",
|
|
"y": "input.y",
|
|
"operation": "input.op",
|
|
},
|
|
}
|
|
tool = FunctionTool.from_dict(data)
|
|
assert tool.name == "calculate"
|
|
assert len(tool.bindings) == 3
|
|
|
|
# Check that all bindings were converted correctly
|
|
binding_names = {b.name for b in tool.bindings}
|
|
assert binding_names == {"x", "y", "operation"}
|
|
|
|
# Check specific binding
|
|
x_binding = next(b for b in tool.bindings if b.name == "x")
|
|
assert x_binding.input == "input.x"
|
|
|
|
|
|
class TestCustomTool:
|
|
"""Tests for CustomTool class."""
|
|
|
|
def test_custom_tool_creation(self):
|
|
tool = CustomTool(
|
|
name="custom_tool",
|
|
description="A custom tool",
|
|
kind="custom",
|
|
options={"endpoint": "https://tool.example.com"},
|
|
)
|
|
assert tool.name == "custom_tool"
|
|
assert tool.kind == "custom"
|
|
assert tool.options == {"endpoint": "https://tool.example.com"}
|
|
|
|
def test_custom_tool_from_dict(self):
|
|
data = {
|
|
"name": "custom_tool",
|
|
"description": "A custom tool",
|
|
"kind": "custom",
|
|
"options": {"endpoint": "https://tool.example.com"},
|
|
}
|
|
tool = CustomTool.from_dict(data)
|
|
assert tool.name == "custom_tool"
|
|
assert tool.kind == "custom"
|
|
|
|
|
|
class TestWebSearchTool:
|
|
"""Tests for WebSearchTool class."""
|
|
|
|
def test_web_search_tool_creation(self):
|
|
tool = WebSearchTool(
|
|
name="web_search",
|
|
description="Search the web",
|
|
kind="web_search",
|
|
options={"maxResults": 10},
|
|
)
|
|
assert tool.name == "web_search"
|
|
assert tool.kind == "web_search"
|
|
assert tool.options == {"maxResults": 10}
|
|
|
|
def test_web_search_tool_from_dict(self):
|
|
data = {
|
|
"name": "web_search",
|
|
"description": "Search the web",
|
|
"kind": "web_search",
|
|
"options": {"maxResults": 10},
|
|
}
|
|
tool = WebSearchTool.from_dict(data)
|
|
assert tool.name == "web_search"
|
|
assert tool.kind == "web_search"
|
|
assert tool.options == {"maxResults": 10}
|
|
|
|
|
|
class TestFileSearchTool:
|
|
"""Tests for FileSearchTool class."""
|
|
|
|
def test_file_search_tool_creation(self):
|
|
tool = FileSearchTool(
|
|
name="file_search",
|
|
description="Search files",
|
|
kind="file_search",
|
|
vectorStoreIds=["vs1", "vs2"],
|
|
)
|
|
assert tool.name == "file_search"
|
|
assert tool.kind == "file_search"
|
|
assert tool.vectorStoreIds == ["vs1", "vs2"]
|
|
|
|
def test_file_search_tool_from_dict(self):
|
|
data = {
|
|
"name": "file_search",
|
|
"description": "Search files",
|
|
"kind": "file_search",
|
|
"vectorStoreIds": ["vs1", "vs2"],
|
|
}
|
|
tool = FileSearchTool.from_dict(data)
|
|
assert tool.name == "file_search"
|
|
assert tool.kind == "file_search"
|
|
assert tool.vectorStoreIds == ["vs1", "vs2"]
|
|
|
|
|
|
class TestMcpServerApprovalMode:
|
|
"""Tests for MCP Server Approval Mode classes."""
|
|
|
|
def test_always_approval_mode(self):
|
|
mode = McpServerToolAlwaysRequireApprovalMode()
|
|
assert mode.kind == "always"
|
|
|
|
def test_always_approval_mode_from_dict(self):
|
|
data = {"kind": "always"}
|
|
mode = McpServerToolAlwaysRequireApprovalMode.from_dict(data)
|
|
assert mode.kind == "always"
|
|
|
|
def test_never_approval_mode(self):
|
|
mode = McpServerToolNeverRequireApprovalMode()
|
|
assert mode.kind == "never"
|
|
|
|
def test_never_approval_mode_from_dict(self):
|
|
data = {"kind": "never"}
|
|
mode = McpServerToolNeverRequireApprovalMode.from_dict(data)
|
|
assert mode.kind == "never"
|
|
|
|
def test_specify_approval_mode(self):
|
|
mode = McpServerToolSpecifyApprovalMode(
|
|
alwaysRequireApprovalTools=["tool1"],
|
|
neverRequireApprovalTools=["tool2"],
|
|
)
|
|
assert mode.kind == "specify"
|
|
assert mode.alwaysRequireApprovalTools == ["tool1"]
|
|
assert mode.neverRequireApprovalTools == ["tool2"]
|
|
|
|
def test_specify_approval_mode_from_dict(self):
|
|
data = {
|
|
"kind": "specify",
|
|
"alwaysRequireApprovalTools": ["tool1"],
|
|
"neverRequireApprovalTools": ["tool2"],
|
|
}
|
|
mode = McpServerToolSpecifyApprovalMode.from_dict(data)
|
|
assert mode.kind == "specify"
|
|
assert mode.alwaysRequireApprovalTools == ["tool1"]
|
|
assert mode.neverRequireApprovalTools == ["tool2"]
|
|
|
|
|
|
class TestMcpTool:
|
|
"""Tests for McpTool class."""
|
|
|
|
def test_mcp_tool_creation(self):
|
|
tool = McpTool(
|
|
name="mcp_tool",
|
|
description="An MCP tool",
|
|
kind="mcp",
|
|
serverName="test-server",
|
|
)
|
|
assert tool.name == "mcp_tool"
|
|
assert tool.kind == "mcp"
|
|
assert tool.serverName == "test-server"
|
|
|
|
def test_mcp_tool_from_dict(self):
|
|
data = {
|
|
"name": "mcp_tool",
|
|
"description": "An MCP tool",
|
|
"kind": "mcp",
|
|
"serverName": "test-server",
|
|
"approvalMode": {"kind": "always"},
|
|
}
|
|
tool = McpTool.from_dict(data)
|
|
assert tool.name == "mcp_tool"
|
|
assert tool.kind == "mcp"
|
|
assert isinstance(tool.approvalMode, McpServerApprovalMode)
|
|
|
|
def test_mcp_tool_with_simplified_approval_mode(self):
|
|
"""Test McpTool with simplified string format for approvalMode."""
|
|
# Test simplified string format: approvalMode: "always"
|
|
data = {
|
|
"name": "mcp_tool",
|
|
"description": "An MCP tool",
|
|
"kind": "mcp",
|
|
"serverName": "test-server",
|
|
"approvalMode": "always",
|
|
}
|
|
tool = McpTool.from_dict(data)
|
|
assert tool.name == "mcp_tool"
|
|
assert tool.kind == "mcp"
|
|
assert isinstance(tool.approvalMode, McpServerApprovalMode)
|
|
assert tool.approvalMode.kind == "always"
|
|
|
|
def test_mcp_tool_approval_mode_equivalence(self):
|
|
"""Test that simplified and full format produce equivalent results."""
|
|
# Simplified format
|
|
data_simplified = {
|
|
"name": "mcp_tool",
|
|
"kind": "mcp",
|
|
"approvalMode": "never",
|
|
}
|
|
tool_simplified = McpTool.from_dict(data_simplified)
|
|
|
|
# Full format
|
|
data_full = {
|
|
"name": "mcp_tool",
|
|
"kind": "mcp",
|
|
"approvalMode": {"kind": "never"},
|
|
}
|
|
tool_full = McpTool.from_dict(data_full)
|
|
|
|
# Both should produce the same result
|
|
assert tool_simplified.approvalMode.kind == tool_full.approvalMode.kind
|
|
assert tool_simplified.approvalMode.kind == "never"
|
|
|
|
|
|
class TestOpenApiTool:
|
|
"""Tests for OpenApiTool class."""
|
|
|
|
def test_openapi_tool_creation(self):
|
|
tool = OpenApiTool(
|
|
name="openapi_tool",
|
|
description="An OpenAPI tool",
|
|
kind="openapi",
|
|
specification="https://api.example.com/openapi.json",
|
|
)
|
|
assert tool.name == "openapi_tool"
|
|
assert tool.kind == "openapi"
|
|
assert tool.specification == "https://api.example.com/openapi.json"
|
|
|
|
def test_openapi_tool_from_dict(self):
|
|
data = {
|
|
"name": "openapi_tool",
|
|
"description": "An OpenAPI tool",
|
|
"kind": "openapi",
|
|
"specification": "https://api.example.com/openapi.json",
|
|
}
|
|
tool = OpenApiTool.from_dict(data)
|
|
assert tool.name == "openapi_tool"
|
|
assert tool.kind == "openapi"
|
|
|
|
|
|
class TestCodeInterpreterTool:
|
|
"""Tests for CodeInterpreterTool class."""
|
|
|
|
def test_code_interpreter_tool_creation(self):
|
|
tool = CodeInterpreterTool(
|
|
name="code_interpreter",
|
|
description="Execute code",
|
|
kind="code_interpreter",
|
|
fileIds=["file1", "file2"],
|
|
)
|
|
assert tool.name == "code_interpreter"
|
|
assert tool.kind == "code_interpreter"
|
|
assert tool.fileIds == ["file1", "file2"]
|
|
|
|
def test_code_interpreter_tool_from_dict(self):
|
|
data = {
|
|
"name": "code_interpreter",
|
|
"description": "Execute code",
|
|
"kind": "code_interpreter",
|
|
"fileIds": ["file1", "file2"],
|
|
}
|
|
tool = CodeInterpreterTool.from_dict(data)
|
|
assert tool.name == "code_interpreter"
|
|
assert tool.kind == "code_interpreter"
|
|
assert tool.fileIds == ["file1", "file2"]
|
|
|
|
|
|
class TestPromptAgent:
|
|
"""Tests for PromptAgent class."""
|
|
|
|
def test_prompt_agent_creation(self):
|
|
agent = PromptAgent(
|
|
name="prompt-agent",
|
|
description="A prompt-based agent",
|
|
instructions="You are a helpful assistant",
|
|
kind="Prompt",
|
|
)
|
|
assert agent.name == "prompt-agent"
|
|
assert agent.kind == "Prompt"
|
|
assert agent.instructions == "You are a helpful assistant"
|
|
|
|
def test_prompt_agent_from_dict(self):
|
|
data = {
|
|
"name": "prompt-agent",
|
|
"description": "A prompt-based agent",
|
|
"instructions": "You are a helpful assistant",
|
|
"kind": "Prompt",
|
|
"model": {"id": "gpt-4"},
|
|
}
|
|
agent = PromptAgent.from_dict(data)
|
|
assert agent.name == "prompt-agent"
|
|
assert isinstance(agent.model, Model)
|
|
assert isinstance(agent.model, Model)
|
|
|
|
def test_prompt_agent_with_tools(self):
|
|
data = {
|
|
"name": "prompt-agent",
|
|
"kind": "Prompt",
|
|
"tools": [
|
|
{"name": "search", "kind": "web_search"},
|
|
{"name": "calc", "kind": "function"},
|
|
],
|
|
}
|
|
agent = PromptAgent.from_dict(data)
|
|
assert len(agent.tools) == 2
|
|
# Tools are converted via Tool.from_dict, type depends on 'kind'
|
|
assert agent.tools[0].kind == "web_search"
|
|
assert agent.tools[1].kind == "function"
|
|
|
|
|
|
class TestResource:
|
|
"""Tests for Resource base class."""
|
|
|
|
def test_resource_creation(self):
|
|
resource = Resource(name="test-resource", kind="Resource")
|
|
assert resource.name == "test-resource"
|
|
assert resource.kind == "Resource"
|
|
|
|
def test_resource_from_dict(self):
|
|
data = {"name": "test-resource", "kind": "Resource"}
|
|
resource = Resource.from_dict(data)
|
|
assert resource.name == "test-resource"
|
|
|
|
|
|
class TestModelResource:
|
|
"""Tests for ModelResource class."""
|
|
|
|
def test_model_resource_creation(self):
|
|
resource = ModelResource(name="my-model", kind="model", id="gpt-4")
|
|
assert resource.name == "my-model"
|
|
assert resource.kind == "model"
|
|
assert resource.id == "gpt-4"
|
|
|
|
def test_model_resource_from_dict(self):
|
|
data = {
|
|
"name": "my-model",
|
|
"kind": "model",
|
|
"id": "gpt-4",
|
|
}
|
|
resource = ModelResource.from_dict(data)
|
|
assert resource.name == "my-model"
|
|
assert resource.kind == "model"
|
|
assert resource.id == "gpt-4"
|
|
|
|
|
|
class TestToolResource:
|
|
"""Tests for ToolResource class."""
|
|
|
|
def test_tool_resource_creation(self):
|
|
resource = ToolResource(name="my-tool", kind="tool", id="search-tool")
|
|
assert resource.name == "my-tool"
|
|
assert resource.kind == "tool"
|
|
assert resource.id == "search-tool"
|
|
|
|
def test_tool_resource_from_dict(self):
|
|
data = {
|
|
"name": "my-tool",
|
|
"kind": "tool",
|
|
"id": "search-tool",
|
|
}
|
|
resource = ToolResource.from_dict(data)
|
|
assert resource.name == "my-tool"
|
|
assert resource.kind == "tool"
|
|
assert resource.id == "search-tool"
|
|
|
|
|
|
class TestProtocolVersionRecord:
|
|
"""Tests for ProtocolVersionRecord class."""
|
|
|
|
def test_protocol_version_record_creation(self):
|
|
record = ProtocolVersionRecord(protocol="mcp", version="1.0.0")
|
|
assert record.protocol == "mcp"
|
|
assert record.version == "1.0.0"
|
|
|
|
def test_protocol_version_record_from_dict(self):
|
|
data = {"protocol": "mcp", "version": "1.0.0"}
|
|
record = ProtocolVersionRecord.from_dict(data)
|
|
assert record.protocol == "mcp"
|
|
assert record.version == "1.0.0"
|
|
|
|
|
|
class TestEnvironmentVariable:
|
|
"""Tests for EnvironmentVariable class."""
|
|
|
|
def test_environment_variable_creation(self):
|
|
env_var = EnvironmentVariable(name="API_KEY", value="secret123")
|
|
assert env_var.name == "API_KEY"
|
|
assert env_var.value == "secret123"
|
|
|
|
def test_environment_variable_from_dict(self):
|
|
data = {"name": "API_KEY", "value": "secret123"}
|
|
env_var = EnvironmentVariable.from_dict(data)
|
|
assert env_var.name == "API_KEY"
|
|
assert env_var.value == "secret123"
|
|
|
|
|
|
class TestTryPowerfxEval:
|
|
"""Tests for _try_powerfx_eval function."""
|
|
|
|
def test_no_evaluation_without_equals_prefix(self):
|
|
"""Test that strings without '=' prefix are returned as-is."""
|
|
assert _try_powerfx_eval("hello") == "hello"
|
|
assert _try_powerfx_eval("test value") == "test value"
|
|
assert _try_powerfx_eval("123") == "123"
|
|
|
|
def test_none_value_returns_none(self):
|
|
"""Test that None values are returned as None."""
|
|
assert _try_powerfx_eval(None) is None
|
|
|
|
def test_empty_string_returns_empty(self):
|
|
"""Test that empty strings are returned as empty."""
|
|
assert _try_powerfx_eval("") == ""
|
|
|
|
def test_simple_powerfx_expressions(self):
|
|
"""Test simple PowerFx expressions."""
|
|
from decimal import Decimal
|
|
|
|
# Simple math - returns Decimal
|
|
assert _try_powerfx_eval("=1 + 2") == Decimal("3")
|
|
assert _try_powerfx_eval("=10 * 5") == Decimal("50")
|
|
|
|
# String literals
|
|
assert _try_powerfx_eval('="hello"') == "hello"
|
|
assert _try_powerfx_eval('="test value"') == "test value"
|
|
|
|
def test_env_variable_access(self, monkeypatch):
|
|
"""Test accessing environment variables using =Env.<name> pattern."""
|
|
# Set up test environment variables
|
|
monkeypatch.setenv("TEST_VAR", "test_value")
|
|
monkeypatch.setenv("API_KEY", "secret123")
|
|
monkeypatch.setenv("PORT", "8080")
|
|
|
|
# Set safe_mode=False to allow environment variable access
|
|
token = _safe_mode_context.set(False)
|
|
try:
|
|
# Test basic env access
|
|
assert _try_powerfx_eval("=Env.TEST_VAR") == "test_value"
|
|
assert _try_powerfx_eval("=Env.API_KEY") == "secret123"
|
|
assert _try_powerfx_eval("=Env.PORT") == "8080"
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
def test_env_variable_with_string_concatenation(self, monkeypatch):
|
|
"""Test env variables with string concatenation operator."""
|
|
monkeypatch.setenv("BASE_URL", "https://api.example.com")
|
|
monkeypatch.setenv("API_VERSION", "v1")
|
|
|
|
# Set safe_mode=False to allow environment variable access
|
|
token = _safe_mode_context.set(False)
|
|
try:
|
|
# Test concatenation with &
|
|
result = _try_powerfx_eval('=Env.BASE_URL & "/" & Env.API_VERSION')
|
|
assert result == "https://api.example.com/v1"
|
|
|
|
# Test concatenation with literals
|
|
result = _try_powerfx_eval('="API Key: " & Env.API_VERSION')
|
|
assert result == "API Key: v1"
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
def test_string_comparison_operators(self, monkeypatch):
|
|
"""Test PowerFx string comparison operators."""
|
|
monkeypatch.setenv("ENV_MODE", "production")
|
|
|
|
# Set safe_mode=False to allow environment variable access
|
|
token = _safe_mode_context.set(False)
|
|
try:
|
|
# Equal to - returns bool
|
|
assert _try_powerfx_eval('=Env.ENV_MODE = "production"') is True
|
|
assert _try_powerfx_eval('=Env.ENV_MODE = "development"') is False
|
|
|
|
# Not equal to - returns bool
|
|
assert _try_powerfx_eval('=Env.ENV_MODE <> "development"') is True
|
|
assert _try_powerfx_eval('=Env.ENV_MODE <> "production"') is False
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
def test_string_in_operator(self):
|
|
"""Test PowerFx 'in' operator for substring testing (case-insensitive)."""
|
|
# Substring test - case insensitive - returns bool
|
|
assert _try_powerfx_eval('="the" in "The keyboard and the monitor"') is True
|
|
assert _try_powerfx_eval('="THE" in "The keyboard and the monitor"') is True
|
|
assert _try_powerfx_eval('="xyz" in "The keyboard and the monitor"') is False
|
|
|
|
def test_string_exactin_operator(self):
|
|
"""Test PowerFx 'exactin' operator for substring testing (case-sensitive)."""
|
|
# Substring test - case sensitive - returns bool
|
|
assert _try_powerfx_eval('="Windows" exactin "To display windows in the Windows operating system"') is True
|
|
assert _try_powerfx_eval('="windows" exactin "To display windows in the Windows operating system"') is True
|
|
assert _try_powerfx_eval('="WINDOWS" exactin "To display windows in the Windows operating system"') is False
|
|
|
|
def test_logical_operators_with_strings(self):
|
|
"""Test PowerFx logical operators (And, Or, Not) with string comparisons."""
|
|
# And operator - returns bool
|
|
assert _try_powerfx_eval('="a" = "a" And "b" = "b"') is True
|
|
assert _try_powerfx_eval('="a" = "a" And "b" = "c"') is False
|
|
|
|
# && operator (alternative syntax) - returns bool
|
|
assert _try_powerfx_eval('="a" = "a" && "b" = "b"') is True
|
|
|
|
# Or operator - returns bool
|
|
assert _try_powerfx_eval('="a" = "b" Or "c" = "c"') is True
|
|
assert _try_powerfx_eval('="a" = "b" Or "c" = "d"') is False
|
|
|
|
# || operator (alternative syntax) - returns bool
|
|
assert _try_powerfx_eval('="a" = "b" || "c" = "c"') is True
|
|
|
|
# Not operator - returns bool
|
|
assert _try_powerfx_eval('=Not("a" = "b")') is True
|
|
assert _try_powerfx_eval('=Not("a" = "a")') is False
|
|
|
|
# ! operator (alternative syntax) - returns bool
|
|
assert _try_powerfx_eval('=!("a" = "b")') is True
|
|
|
|
def test_parentheses_for_precedence(self):
|
|
"""Test using parentheses to control operator precedence."""
|
|
from decimal import Decimal
|
|
|
|
# Test arithmetic precedence - returns Decimal
|
|
assert _try_powerfx_eval("=(1 + 2) * 3") == Decimal("9")
|
|
assert _try_powerfx_eval("=1 + 2 * 3") == Decimal("7")
|
|
|
|
# Test logical precedence - returns bool
|
|
result = _try_powerfx_eval('=("a" = "a" Or "b" = "c") And "d" = "d"')
|
|
assert result is True
|
|
|
|
def test_env_with_special_characters(self, monkeypatch):
|
|
"""Test env variables containing special characters in values."""
|
|
monkeypatch.setenv("URL_WITH_QUERY", "https://example.com?param=value")
|
|
monkeypatch.setenv("PATH_WITH_SPACES", "C:\\Program Files\\App")
|
|
|
|
# Set safe_mode=False to allow environment variable access
|
|
token = _safe_mode_context.set(False)
|
|
try:
|
|
result = _try_powerfx_eval("=Env.URL_WITH_QUERY")
|
|
assert result == "https://example.com?param=value"
|
|
|
|
result = _try_powerfx_eval("=Env.PATH_WITH_SPACES")
|
|
assert result == "C:\\Program Files\\App"
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
def test_safe_mode_blocks_env_access(self, monkeypatch):
|
|
"""Test that safe_mode=True (default) blocks environment variable access."""
|
|
monkeypatch.setenv("SECRET_VAR", "secret_value")
|
|
|
|
# Set safe_mode=True (default)
|
|
token = _safe_mode_context.set(True)
|
|
try:
|
|
# When safe_mode=True, Env is not available and the expression fails,
|
|
# returning the original value
|
|
result = _try_powerfx_eval("=Env.SECRET_VAR")
|
|
assert result == "=Env.SECRET_VAR"
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
def test_safe_mode_context_isolation(self, monkeypatch):
|
|
"""Test that safe_mode context variable properly isolates env access."""
|
|
monkeypatch.setenv("TEST_VAR", "test_value")
|
|
|
|
# First, set safe_mode=True - should NOT allow env access
|
|
token = _safe_mode_context.set(True)
|
|
try:
|
|
result_safe = _try_powerfx_eval("=Env.TEST_VAR")
|
|
assert result_safe == "=Env.TEST_VAR"
|
|
|
|
# Then, set safe_mode=False - should allow env access
|
|
token2 = _safe_mode_context.set(False)
|
|
try:
|
|
result_unsafe = _try_powerfx_eval("=Env.TEST_VAR")
|
|
assert result_unsafe == "test_value"
|
|
finally:
|
|
_safe_mode_context.reset(token2)
|
|
|
|
# After reset, should block again
|
|
result_safe_again = _try_powerfx_eval("=Env.TEST_VAR")
|
|
assert result_safe_again == "=Env.TEST_VAR"
|
|
finally:
|
|
_safe_mode_context.reset(token)
|
|
|
|
|
|
class TestAgentManifest:
|
|
"""Tests for AgentManifest class."""
|
|
|
|
def test_agent_manifest_creation(self):
|
|
manifest = AgentManifest(name="my-agent-manifest", description="A test manifest")
|
|
assert manifest.name == "my-agent-manifest"
|
|
assert manifest.description == "A test manifest"
|
|
|
|
def test_agent_manifest_from_dict(self):
|
|
data = {
|
|
"name": "my-agent-manifest",
|
|
"description": "A test manifest",
|
|
}
|
|
manifest = AgentManifest.from_dict(data)
|
|
assert manifest.name == "my-agent-manifest"
|
|
|
|
def test_agent_manifest_with_resources(self):
|
|
data = {
|
|
"name": "my-agent-manifest",
|
|
"resources": [
|
|
{"name": "model1", "kind": "model", "id": "gpt-4"},
|
|
{
|
|
"name": "tool1",
|
|
"kind": "tool",
|
|
"id": "search-tool",
|
|
},
|
|
],
|
|
}
|
|
manifest = AgentManifest.from_dict(data)
|
|
assert manifest.name == "my-agent-manifest"
|
|
assert len(manifest.resources) == 2
|
|
# Resources are converted via Resource.from_dict based on their 'kind'
|
|
assert isinstance(manifest.resources[0], ModelResource)
|
|
assert isinstance(manifest.resources[1], ToolResource)
|
|
|
|
def test_agent_manifest_complete(self):
|
|
"""Test a complete agent manifest with all fields."""
|
|
data = {
|
|
"name": "complete-manifest",
|
|
"description": "A complete test manifest",
|
|
"template": {
|
|
"name": "assistant",
|
|
"kind": "Prompt",
|
|
"description": "A helpful assistant",
|
|
},
|
|
"resources": [
|
|
{"name": "model1", "kind": "model", "id": "gpt-4"},
|
|
],
|
|
}
|
|
manifest = AgentManifest.from_dict(data)
|
|
assert manifest.name == "complete-manifest"
|
|
assert isinstance(manifest.template, AgentDefinition)
|
|
assert len(manifest.resources) == 1
|
|
assert isinstance(manifest.resources[0], ModelResource)
|
|
|
|
def test_agent_manifest_with_dict_resources(self):
|
|
"""Test AgentManifest with dict format for resources (MAML YAML dict syntax)."""
|
|
data = {
|
|
"name": "manifest-with-dict-resources",
|
|
"description": "Test manifest with dict resources",
|
|
"resources": {
|
|
"gptModelDeployment": {"kind": "model", "id": "gpt-4o"},
|
|
"webSearchInstance": {"kind": "tool", "id": "web-search"},
|
|
"analyticsTool": {"kind": "tool", "id": "analytics"},
|
|
},
|
|
}
|
|
manifest = AgentManifest.from_dict(data)
|
|
assert manifest.name == "manifest-with-dict-resources"
|
|
assert len(manifest.resources) == 3
|
|
|
|
# Check that all resources were converted correctly
|
|
resource_names = {r.name for r in manifest.resources}
|
|
assert resource_names == {"gptModelDeployment", "webSearchInstance", "analyticsTool"}
|
|
|
|
# Check specific resource
|
|
gpt_resource = next(r for r in manifest.resources if r.name == "gptModelDeployment")
|
|
assert isinstance(gpt_resource, ModelResource)
|
|
assert gpt_resource.id == "gpt-4o"
|
|
|
|
web_resource = next(r for r in manifest.resources if r.name == "webSearchInstance")
|
|
assert isinstance(web_resource, ToolResource)
|
|
assert web_resource.id == "web-search"
|