westey ff3e13c2aa .Net: Add support for 3rd party thread storage and thread serialization (#203)
* Add thread storage and serialization POC

* Switch to using JsonElement and add unit tests

* Add additional unit tests.

* Exclude private debugger properties from CodeCoverage.

* Rename IChatMessagesStorable to IChatMessageStore

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Improve xml doc.

* Update the message storing thread to always use external store for both local and remote storage.

* Remove threadid from the IChatMessageStore interface, since the store should own the thread id itself, if it requires one.

* Switch GetMessages to IEnumerable

* Address pr comments.

* Make jsonserializer options default consistent on DeserializeThreadAsync

* Move message storing thread functionality into AgentThread and simplify AgentThread behavior.

* Remove embedding generation from VectorStore chat history sample.

* Remove unecessary code and fix formatting.

* Make GetNewThread and DeserializeThread virtual with default implementations.
Remove unsued json utilities.

* Fix formatting

* Remove problem test.

* Add more unit tests

* Remove unused using clause.

* Address pr feedback.

* Address PR comments.

* Make InMemory store internal

* Switch InMemoryChatMessageStore to implement IList instead of inheriting from List.

* Rename store deserialize param.

* Update serialization based on PR comments.

* Remove confusing comment.

* Address Deserialization PR comments in the same way as Serialization

* Add State to IChatMessageStore Serialize and Deserialize names.
Make Thread Deserialize internal.
Make AgentThread type switching fobidden.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
ff3e13c2aa · 2025-08-05 17:24:25 +00:00
149 Commits
2025-08-05 14:39:24 +00:00
2025-04-28 12:54:43 -07:00
2025-04-28 12:54:42 -07:00
2025-04-28 12:54:43 -07:00

Get Started with Microsoft Agent Framework

Highlights

  • Flexible Agent Framework: build, orchestrate, and deploy AI agents and multi-agent systems
  • Multi-Agent Orchestration: Group chat, sequential, concurrent, and handoff patterns
  • Plugin Ecosystem: Extend with native functions, OpenAPI, Model Context Protocol (MCP), and more
  • LLM Support: OpenAI, Azure OpenAI, Azure AI Foundry, and more
  • Runtime Support: In-process and distributed agent execution
  • Multimodal: Text, vision, and function calling
  • Cross-Platform: .NET and Python implementations

Below are the basics for each language implementation. For more details on python see here and for .NET see here.

Python - Quick Install

pip install agent-framework
# Optional: Add Azure integration
pip install agent-framework[azure]
# Optional: Add Foundry integration
pip install agent-framework[foundry]
# Optional: Both
pip install agent-framework[azure,foundry]

Supported Platforms:

  • Python: 3.10+
  • OS: Windows, macOS, Linux

Python - 1. Setup API Keys

Set as environment variables, or create a .env file at your project root:

OPENAI_API_KEY=sk-...
OPENAI_CHAT_MODEL_ID=...
OPENAI_RESPONSES_MODEL_ID=...
...
AZURE_OPENAI_API_KEY=...
AZURE_OPENAI_ENDPOINT=...
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=...
...
FOUNDRY_PROJECT_ENDPOINT=...
FOUNDRY_MODEL_DEPLOYMENT_NAME=...

You can also override environment variables by explicitly passing configuration parameters to the chat client constructor:

from agent_framework.azure import AzureChatClient

chat_client = AzureChatClient(
    api_key=...,
    endpoint=...,
    deployment_name=...,
    api_version=...,
)

See the following setup guide for more information.

Python - 2. Create a Simple Agent

Create agents and invoke them directly:

import asyncio
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient

async def main():
    async with ChatClientAgent(
        chat_client=FoundryChatClient(),
        instructions="""These are the Three Laws of Robotics:
        1) A robot may not injure a human being...
        2) A robot must obey orders given it by human beings...
        3) A robot must protect its own existence...

        Respond concisely to the user's request.
        """
    ):
        result = await agent.run("Summarize the Three Laws of Robotics")
        print(result.text)
        """
        Output:
        Protect humans, obey, self-preserve, prioritized.
        """

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

Python - 3. Build an Agent with Tools

Enhance your agent with custom tools and function calling:

import asyncio
from typing import Annotated
from random import randint
from pydantic import Field
from agent_framework import ChatClientAgent
from agent_framework.openai import OpenAIResponsesClient


def get_weather(
    location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
    """Get the weather for a given location."""
    conditions = ["sunny", "cloudy", "rainy", "stormy"]
    return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."


def get_menu_specials() -> str:
    """Get today's menu specials."""
    return """
    Special Soup: Clam Chowder
    Special Salad: Cobb Salad
    Special Drink: Chai Tea
    """


async def main():
    agent = ChatClientAgent(
        chat_client=OpenAIResponsesClient(),
        instructions="You are a helpful assistant that can provide weather and restaurant information.",
        tools=[get_weather, get_menu_specials]
    )

    response = await agent.run("What's the weather in Amsterdam and what are today's specials?")
    print(response.text)

    """
    Output:
    The weather in Amsterdam is sunny with a high of 22°C. Today's specials include
    Clam Chowder soup, Cobb Salad, and Chai Tea as the special drink.
    """

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

You can explore additional agent samples here.

Note: Advanced orchestration patterns like GroupChat, Sequential, and Concurrent orchestrations are coming soon.

More Examples & Samples

Agent Framework Documentation

Languages
Python 50.9%
C# 45.8%
TypeScript 2.7%
HTML 0.2%
PowerShell 0.1%
Other 0.1%