Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/agents-a365-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,53 @@ npm install @microsoft/agents-a365-runtime

## Usage

### Agent Settings Service

The Agent Settings Service provides methods to manage agent settings templates and instance-specific settings:

```typescript
import {
AgentSettingsService,
PowerPlatformApiDiscovery
} from '@microsoft/agents-a365-runtime';

// Initialize the service
const apiDiscovery = new PowerPlatformApiDiscovery('prod');
const tenantId = 'your-tenant-id';
const service = new AgentSettingsService(apiDiscovery, tenantId);

// Get agent setting template by agent type
const template = await service.getAgentSettingTemplate(
'my-agent-type',
accessToken
);

// Set agent setting template
await service.setAgentSettingTemplate(
{
agentType: 'my-agent-type',
settings: { key1: 'value1', key2: 'value2' }
},
accessToken
);

// Get agent settings by instance
const settings = await service.getAgentSettings(
'agent-instance-id',
accessToken
);

// Set agent settings by instance
await service.setAgentSettings(
{
agentInstanceId: 'agent-instance-id',
agentType: 'my-agent-type',
settings: { instanceKey: 'instanceValue' }
},
accessToken
);
```

For detailed usage examples and implementation guidance, see the [Microsoft Agent 365 Developer Documentation](https://learn.microsoft.com/microsoft-agent-365/developer/?tabs=nodejs).

## Support
Expand Down
212 changes: 212 additions & 0 deletions packages/agents-a365-runtime/src/agent-settings-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { PowerPlatformApiDiscovery } from './power-platform-api-discovery';

/**
* Represents an agent setting template.
*/
export interface AgentSettingTemplate {
/**
* The agent type identifier.
*/
agentType: string;

/**
* The settings template as a key-value dictionary.
*/
settings: Record<string, unknown>;

/**
* Optional metadata about the template.
*/
metadata?: Record<string, unknown>;
}

/**
* Represents agent settings for a specific instance.
*/
export interface AgentSettings {
/**
* The agent instance identifier.
*/
agentInstanceId: string;

/**
* The agent type identifier.
*/
agentType: string;

/**
* The settings as a key-value dictionary.
*/
settings: Record<string, unknown>;

/**
* Optional metadata about the settings.
*/
metadata?: Record<string, unknown>;
}

/**
* Service for managing agent settings templates and instance-specific settings.
*/
export class AgentSettingsService {
private readonly apiDiscovery: PowerPlatformApiDiscovery;
private readonly tenantId: string;

/**
* Creates a new instance of AgentSettingsService.
* @param apiDiscovery The Power Platform API discovery service.
* @param tenantId The tenant identifier.
*/
constructor(apiDiscovery: PowerPlatformApiDiscovery, tenantId: string) {
this.apiDiscovery = apiDiscovery;
this.tenantId = tenantId;
}

/**
* Gets the base endpoint for agent settings API.
* @returns The base endpoint URL.
*/
private getBaseEndpoint(): string {
const tenantEndpoint = this.apiDiscovery.getTenantEndpoint(this.tenantId);
return `https://${tenantEndpoint}/agents/v1.0`;
}

/**
* Gets the endpoint for agent setting templates.
* @param agentType The agent type identifier.
* @returns The endpoint URL for the agent type template.
*/
public getAgentSettingTemplateEndpoint(agentType: string): string {
return `${this.getBaseEndpoint()}/settings/templates/${encodeURIComponent(agentType)}`;
}

/**
* Gets the endpoint for agent instance settings.
* @param agentInstanceId The agent instance identifier.
* @returns The endpoint URL for the agent instance settings.
*/
public getAgentSettingsEndpoint(agentInstanceId: string): string {
return `${this.getBaseEndpoint()}/settings/instances/${encodeURIComponent(agentInstanceId)}`;
}

/**
* Retrieves an agent setting template by agent type.
* @param agentType The agent type identifier.
* @param accessToken The access token for authentication.
* @returns A promise that resolves to the agent setting template.
*/
public async getAgentSettingTemplate(
agentType: string,
accessToken: string
): Promise<AgentSettingTemplate> {
const endpoint = this.getAgentSettingTemplateEndpoint(agentType);

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();
}
Comment on lines +107 to +122
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

/**
* Sets an agent setting template for a specific agent type.
* @param template The agent setting template to set.
* @param accessToken The access token for authentication.
* @returns A promise that resolves to the updated agent setting template.
*/
public async setAgentSettingTemplate(
template: AgentSettingTemplate,
accessToken: string
): Promise<AgentSettingTemplate> {
const endpoint = this.getAgentSettingTemplateEndpoint(template.agentType);

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();
}
Comment on lines +136 to +152
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

/**
* Retrieves agent settings for a specific agent instance.
* @param agentInstanceId The agent instance identifier.
* @param accessToken The access token for authentication.
* @returns A promise that resolves to the agent settings.
*/
public async getAgentSettings(
agentInstanceId: string,
accessToken: string
): Promise<AgentSettings> {
const endpoint = this.getAgentSettingsEndpoint(agentInstanceId);

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();
}
Comment on lines +166 to +181
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

/**
* Sets agent settings for a specific agent instance.
* @param settings The agent settings to set.
* @param accessToken The access token for authentication.
* @returns A promise that resolves to the updated agent settings.
*/
public async setAgentSettings(
settings: AgentSettings,
accessToken: string
): Promise<AgentSettings> {
const endpoint = this.getAgentSettingsEndpoint(settings.agentInstanceId);

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();
}
Comment on lines +195 to +211
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
}
3 changes: 2 additions & 1 deletion packages/agents-a365-runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './power-platform-api-discovery';
export * from './agentic-authorization-service';
export * from './environment-utils';
export * from './utility';
export * from './utility';
export * from './agent-settings-service';
Loading