Skip to content
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

.Net: Phase 1 of the declarative agent schema for review #10260

Open
wants to merge 31 commits into
base: feature-declarative-agents
Choose a base branch
from

Conversation

markwallace-microsoft
Copy link
Member

@markwallace-microsoft markwallace-microsoft commented Jan 22, 2025

Motivation and Context

Related #10224

Includes following

  • Model classes for the Agent Definition
  • An Agent Factory abstraction which is used to create an Agent instance from it's serialised form
  • Agent Factory implementations for Chat Completion, OpenAI Assistant and AzureAI Agent implementations

Description

Contribution Checklist

@markwallace-microsoft markwallace-microsoft force-pushed the users/markwallace/adr_declarative_agents branch from c624bbd to e800600 Compare January 28, 2025 09:19
@joslat
Copy link
Contributor

joslat commented Feb 5, 2025

Hi @markwallace-microsoft,
here is some feedback, hope it helps... I think it is great to support Declarative formats, maybe I'd make some base support for YAML and JSON as "base declarative formats" and implement custom plugins on top that support the existing declarative formats supported and the proposed Microsoft 365 copilot. this could make it easier to implement and add any new declarative format.

Maybe support:

  • Copilot Studio Agents? (I thnink a format json-yaml is generated below the hood to drive behavior...)
  • Azure AI Foundry Agents / Azure AI Agents (I believe this is code but with declarative style, though haven't explored it yet... still need to check Chris bits added some days ago - essentially I don't know what I am talking about and making an hypothesis)
  • AutoGen (in the studio there is a yaml/json definition that is used to persist an agent, so that could, might be a thing)
  • Other: unsure other frameworks like langgraph, langchain, crew ai, swarm, amazon bedrock or google services have a declarative format...

Unsure this helps, pretty much high level.

@markwallace-microsoft
Copy link
Member Author

Hi @markwallace-microsoft, here is some feedback, hope it helps... I think it is great to support Declarative formats, maybe I'd make some base support for YAML and JSON as "base declarative formats" and implement custom plugins on top that support the existing declarative formats supported and the proposed Microsoft 365 copilot. this could make it easier to implement and add any new declarative format.

Maybe support:

  • Copilot Studio Agents? (I thnink a format json-yaml is generated below the hood to drive behavior...)
  • Azure AI Foundry Agents / Azure AI Agents (I believe this is code but with declarative style, though haven't explored it yet... still need to check Chris bits added some days ago - essentially I don't know what I am talking about and making an hypothesis)
  • AutoGen (in the studio there is a yaml/json definition that is used to persist an agent, so that could, might be a thing)
  • Other: unsure other frameworks like langgraph, langchain, crew ai, swarm, amazon bedrock or google services have a declarative format...

Unsure this helps, pretty much high level.

Thanks for the feedback @joslat

  • I'm using YAML in the document for my samples nut JSON would also be supported
  • The goal is to have a format which is Agent Service agnostic and will support Azure AI Agents, OpenAI Assistants, Chat Completion Agents, AutoGen, etc.
  • Another goal to be able able to convert from other formats to this one.

@markwallace-microsoft markwallace-microsoft requested a review from a team as a code owner February 19, 2025 14:00
@markwallace-microsoft markwallace-microsoft changed the base branch from main to feature-declarative-agents February 20, 2025 14:57
@markwallace-microsoft markwallace-microsoft changed the title Initial draft of the declarative agent schema for review Phase 1 of the declarative agent schema for review Feb 20, 2025
@markwallace-microsoft markwallace-microsoft changed the base branch from feature-declarative-agents to main February 20, 2025 18:04
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label Feb 21, 2025
@markwallace-microsoft markwallace-microsoft changed the title Phase 1 of the declarative agent schema for review .NET: Phase 1 of the declarative agent schema for review Feb 21, 2025
@markwallace-microsoft markwallace-microsoft changed the base branch from main to feature-declarative-agents February 21, 2025 19:38
@markwallace-microsoft markwallace-microsoft marked this pull request as ready for review February 21, 2025 19:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 79 out of 79 changed files in this pull request and generated 3 comments.

/// <summary>
/// Tool definition type for code interpreter.
/// </summary>
public const string CodeInterpreter = "code_interpreter";
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the plan for 5 other tools introduced for Azure AI Agents?

(imho) code_interpreter and file_search are implementation specific and perhaps don't belong in the abstraction?

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking is to include things that are cross service in the abstraction and others in the specific package, so the openai, bing etc. that Azure AI supports would go into that package.

Copy link
Contributor

Choose a reason for hiding this comment

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

These aren't always available for every agent service (e.g. ChatCompletion). At best, it still strikes me as an over-generalization that doesn't have a lot of impact/value compared to the alternative. On the down side, it could create both implementation and usage confusion.

/// Determines if the agent definition has a code interpreter tool.
/// </summary>
/// <param name="agentDefinition">Agent definition</param>
public static bool IsEnableCodeInterpreter(this AgentDefinition agentDefinition)
Copy link
Contributor

Choose a reason for hiding this comment

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

In alignment with previous comment, these might more propertly be defined on the agent specific extensions in the respective packages/projects.

if (agentDefinition.Type?.Equals(OpenAIAssistantAgentType, System.StringComparison.Ordinal) ?? false)
{
var clientProvider = kernel.GetOpenAIClientProvider(agentDefinition);
AssistantClient client = clientProvider.Client.GetAssistantClient();
Copy link
Contributor

Choose a reason for hiding this comment

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

The client-provider pattern is being deprecated in favor of direct client usage.

KernelAgent? kernelAgent = null;
if (agentDefinition.Type?.Equals(AzureAIAgentType, System.StringComparison.Ordinal) ?? false)
{
var clientProvider = kernel.GetAzureAIClientProvider(agentDefinition);
Copy link
Contributor

Choose a reason for hiding this comment

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

The client-provider pattern is being deprecated in favor of direct client usage.

};
}

return Task.FromResult<KernelAgent?>(kernelAgent).Result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return kernelAgent; problematic?

};
}

return Task.FromResult<KernelAgent?>(kernelAgent).Result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return kernelAgent; problematic?

@crickman
Copy link
Contributor

Adding support for BedrockAgent?

/// <param name="agentDefinition">Definition of the agent to create.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <return>The created <see cref="KernelAgent"/>, if null the agent type is not supported.</return>
public abstract Task<KernelAgent?> CreateAsync(Kernel kernel, AgentDefinition agentDefinition, CancellationToken cancellationToken = default);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the factory cannot produce the agent, perhaps it should throw instead of returning null? (change return type to Task<KernelAgent>?)

Verify.NotNull(agentDefinition.Model.Id);

KernelAgent? kernelAgent = null;
if (agentDefinition.Type?.Equals(OpenAIAssistantAgentType, System.StringComparison.Ordinal) ?? false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't type validation be performed as a protected method in KernelAgentFactory since Types is defined in the base abstraction? Then each factory won't have to implement custom validation. They can just call into the base method.

@crickman
Copy link
Contributor

Be nice to see some comprehensive samples on this.

@crickman
Copy link
Contributor

Any thoughts on reconciling the support for the PromptTemplateConfig with this new pattern? (Will both be supported or will we be preferring this new pattern for agents?)

@crickman
Copy link
Contributor

Is this going to be released as "GA" or have an experimental tag defined?

Verify.NotNull(agentDefinition);

// Use the agent configuration as the first option
var configuration = agentDefinition?.Model?.Configuration;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect that developers will not want to (or be allowed to) store secrets such as ApiKey in the agent manifest.

Supporting the ability to resolve environment variables (at a minimum) or resolve other configurations settings may be prudent to consider.

#security

{
var hasEndpoint = configuration.TryGetValue(Endpoint, out var endpoint) && endpoint is not null;
var hasApiKey = configuration.TryGetValue(ApiKey, out var apiKey) && apiKey is not null;
if (hasApiKey && hasEndpoint)
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic may be overly brittle. Isn't there the case where a non-azure endpoint can be targeted that requires an endpoint (such as a model gateway)?

It might be prudent to require explicit knowledge on whether Azure or OpenAI is intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation .NET Issue or Pull requests regarding .NET code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants