Declarative support for Microsoft Agent Framework

1.0.0b260409 · active · verified Thu Apr 16

agent-framework-declarative provides declarative specification support for defining AI agents and workflows using YAML or JSON files within the Microsoft Agent Framework. It enables easier agent definition, modification, and sharing, serving as a key component of the broader Agent Framework which unifies capabilities from Semantic Kernel and AutoGen. As of April 2026, the main Agent Framework is stable at version 1.0.1, while this specific declarative package is in beta (1.0.0b260409), indicating a rapid release cadence for this component.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple agent using a YAML file and then load and run it using `AgentFactory.create_agent_from_yaml`. It uses placeholder environment variables for model connection, which should be configured with actual values for execution.

import os
import asyncio
from agent_framework import AgentFactory

# Create a dummy YAML file for the declarative agent
agent_yaml_content = """
name: GreetingAgent
description: An agent that greets the user.
instructions: "You are a friendly agent that responds to greetings. If asked 'What can you do for me?', state your purpose as a greeting agent."
model:
  id: =Env.AZURE_OPENAI_MODEL # Use environment variable for model ID
  connection:
    kind: remote
    endpoint: =Env.FOUNDRY_PROJECT_ENDPOINT # Use environment variable for endpoint
"""

with open("greeting-agent.yaml", "w") as f:
    f.write(agent_yaml_content)

async def run_declarative_agent():
    # Ensure environment variables are set for model connection
    os.environ['AZURE_OPENAI_MODEL'] = os.environ.get('AZURE_OPENAI_MODEL', 'gpt-4')
    os.environ['FOUNDRY_PROJECT_ENDPOINT'] = os.environ.get('FOUNDRY_PROJECT_ENDPOINT', 'http://localhost:5000/v1') # Placeholder

    print("Loading agent from YAML...")
    async with AgentFactory().create_agent_from_yaml("greeting-agent.yaml") as agent:
        print(f"Agent '{agent.name}' loaded. Description: {agent.description}")
        response = await agent.run("Hello, Agent!")
        print("Agent response (Hello):", response.text)

        response_purpose = await agent.run("What can you do for me?")
        print("Agent response (Purpose):", response_purpose.text)

if __name__ == "__main__":
    asyncio.run(run_declarative_agent())

view raw JSON →