Add Agent Settings Service with template and instance management#130
Add Agent Settings Service with template and instance management#130
Conversation
…nces Co-authored-by: sergioescalera <8428450+sergioescalera@users.noreply.github.com>
Co-authored-by: sergioescalera <8428450+sergioescalera@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds the Agent Settings Service to the @microsoft/agents-a365-runtime package, implementing API methods for managing agent configuration templates by type and instance-specific settings. The implementation provides both template-level and instance-level CRUD operations via the Power Platform API.
- Introduces
AgentSettingsServiceclass with methods for getting/setting templates and instance settings - Defines TypeScript interfaces (
AgentSettingTemplateandAgentSettings) with flexible key-value settings and optional metadata - Includes comprehensive test suite with mocking, error handling tests, and endpoint verification
- Updates documentation with usage examples
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
packages/agents-a365-runtime/src/agent-settings-service.ts |
New service implementing template and instance settings management with Power Platform API integration |
packages/agents-a365-runtime/src/index.ts |
Exports the new AgentSettingsService and related types |
tests/runtime/agent-settings-service.test.ts |
Comprehensive test suite covering CRUD operations, error handling, and endpoint construction |
packages/agents-a365-runtime/README.md |
Documentation with usage examples for the Agent Settings Service |
| const response = await fetch(endpoint, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to get agent setting template for type '${agentType}': ${response.status} ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return await response.json(); | ||
| } |
There was a problem hiding this comment.
The fetch call lacks error handling for network failures and JSON parsing errors. If the network request fails (e.g., network timeout, DNS failure) or if the response body is not valid JSON, an unhandled exception will be thrown. Consider wrapping the fetch and json parsing in a try-catch block to provide more informative error messages to callers.
| const response = await fetch(endpoint, { | ||
| method: 'PUT', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(template), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to set agent setting template for type '${template.agentType}': ${response.status} ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return await response.json(); | ||
| } |
There was a problem hiding this comment.
The fetch call lacks error handling for network failures and JSON parsing errors. If the network request fails (e.g., network timeout, DNS failure) or if the response body is not valid JSON, an unhandled exception will be thrown. Consider wrapping the fetch and json parsing in a try-catch block to provide more informative error messages to callers.
| const response = await fetch(endpoint, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to get agent settings for instance '${agentInstanceId}': ${response.status} ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return await response.json(); | ||
| } |
There was a problem hiding this comment.
The fetch call lacks error handling for network failures and JSON parsing errors. If the network request fails (e.g., network timeout, DNS failure) or if the response body is not valid JSON, an unhandled exception will be thrown. Consider wrapping the fetch and json parsing in a try-catch block to provide more informative error messages to callers.
| const response = await fetch(endpoint, { | ||
| method: 'PUT', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(settings), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to set agent settings for instance '${settings.agentInstanceId}': ${response.status} ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return await response.json(); | ||
| } |
There was a problem hiding this comment.
The fetch call lacks error handling for network failures and JSON parsing errors. If the network request fails (e.g., network timeout, DNS failure) or if the response body is not valid JSON, an unhandled exception will be thrown. Consider wrapping the fetch and json parsing in a try-catch block to provide more informative error messages to callers.
| it.each<{ cluster: ClusterCategory; expectedDomain: string }>([ | ||
| { cluster: 'prod', expectedDomain: 'api.powerplatform.com' }, | ||
| { cluster: 'gov', expectedDomain: 'api.gov.powerplatform.microsoft.us' }, | ||
| { cluster: 'high', expectedDomain: 'api.high.powerplatform.microsoft.us' }, | ||
| ])('should construct endpoint with correct domain for $cluster cluster', ({ cluster, expectedDomain }) => { | ||
| const discovery = new PowerPlatformApiDiscovery(cluster); | ||
| const testService = new AgentSettingsService(discovery, testTenantId); | ||
|
|
||
| const endpoint = testService.getAgentSettingTemplateEndpoint(testAgentType); | ||
|
|
||
| expect(endpoint).toContain(expectedDomain); | ||
| expect(endpoint).toContain('/agents/v1.0/settings/templates/'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The cluster category test coverage is incomplete. Only 3 of the 13 supported cluster categories are tested (prod, gov, high), while PowerPlatformApiDiscovery supports 13 categories (local, dev, test, preprod, firstrelease, prod, gov, high, dod, mooncake, ex, rx). Following the pattern in power-platform-api-discovery.test.ts, consider testing all cluster categories or at least a more representative subset to ensure the service works correctly across all environments.
🤖 SDK Parity AutomationSummaryThis PR modifies the Node.js/TypeScript SDK. To maintain feature parity across all SDKs, Existing open parity issues were found:
What happens next?
Need to skip parity?If parity is not needed for a particular SDK, close the corresponding issue with the Automated by AI-First Polling Workflow |
Implements the Agent Settings API for managing agent configuration templates by type and instance-specific settings.
Changes
AgentSettingsService - New service class in
@microsoft/agents-a365-runtimewith methods:getAgentSettingTemplate/setAgentSettingTemplate- Manage templates by agent typegetAgentSettings/setAgentSettings- Manage settings by agent instance IDType definitions -
AgentSettingTemplateandAgentSettingsinterfaces with settings asRecord<string, unknown>and optional metadataEndpoints - Constructs Power Platform API URLs:
/agents/v1.0/settings/templates/{agentType}/agents/v1.0/settings/instances/{agentInstanceId}Usage
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.