Skip to content

[bot] Add Semantic Kernel Python SDK integration for ChatCompletionAgent, Kernel, and multi-agent orchestration instrumentation #500

@braintrust-bot

Description

@braintrust-bot

Summary

The Semantic Kernel Python SDK (semantic-kernel) is Microsoft's production-ready AI orchestration framework for building agents, multi-agent systems, and LLM-powered applications. It is actively maintained with weekly releases (v1.43.0, June 3, 2026) and ~23k GitHub stars. This repository has zero instrumentation for any Semantic Kernel Python execution surface — no integration directory, no wrapper, no patcher, no auto_instrument() support.

Semantic Kernel provides a ChatCompletionAgent for single- and multi-turn agent execution, a Kernel for direct prompt and plugin invocation, and multi-agent orchestration patterns (AgentGroupChat, GroupChatOrchestration). These are distinct from the agent-framework package covered by issue #197 — Semantic Kernel is a separate, actively maintained PyPI package with its own execution APIs and user base.

Comparable agent frameworks with dedicated Python integrations in this repo: openai-agents, claude-agent-sdk, google-adk, pydantic-ai, agno, crewai, autogen-agentchat, strands-agents, livekit-agents.

What needs to be instrumented

The semantic-kernel package exposes these execution surfaces, none of which are instrumented:

Agent execution (highest priority)

SDK Method Description Return type
ChatCompletionAgent.get_response(messages, thread=...) Single agent response (async) AgentResponseItem[ChatMessageContent]
ChatCompletionAgent.invoke(messages, thread=...) Multi-turn agent execution, yields responses (async iterable) AsyncIterable[AgentResponseItem[ChatMessageContent]]
ChatCompletionAgent.invoke_stream(messages, thread=...) Streaming agent execution (async iterable) AsyncIterable[StreamingChatMessageContent]

get_response() is the primary entry point for single-shot agent calls. invoke() and invoke_stream() support multi-turn conversations with tool use via a ChatHistoryAgentThread. All are async.

Each invocation may involve multiple internal LLM calls if the agent uses plugins/tools — the integration should create a parent span for the agent invocation and child spans for tool calls (FunctionCallContent, FunctionResultContent).

Kernel-level prompt and function invocation

SDK Method Description Return type
Kernel.invoke(function, arguments=...) Execute a prompt function or plugin function (async) FunctionResult
Kernel.invoke_stream(function, arguments=...) Streaming execution of a prompt function (async iterable) AsyncIterable[StreamingChatMessageContent]
Kernel.invoke_prompt(prompt, arguments=...) Inline prompt execution (async) FunctionResult

The Kernel class is the core orchestration unit. invoke() runs a KernelFunction (either a prompt template or a Python plugin function). invoke_prompt() takes an inline prompt string and executes it directly against the configured AI service.

Multi-agent orchestration

Class Description
AgentGroupChat Manages a conversation among multiple agents, iterating until a termination condition is met
GroupChatOrchestration Higher-level orchestration pattern (Sequential, Concurrent, RoundRobin, Handoff, Magentic)

AgentGroupChat.invoke() drives a group conversation with multiple ChatCompletionAgent instances. The integration should create a parent span for the group chat and child spans per participating agent turn.

AI service connectors (lower priority — covered if agent/kernel is instrumented)

The underlying AI service connectors (OpenAIChatCompletion, AzureChatCompletion, AnthropicChatCompletion, etc.) call providers already instrumented in this repo. Instrumenting the agent/kernel layer captures the full agent execution context even without re-instrumenting the provider layer.

Implementation notes

Async-first API: All primary execution APIs are async (await agent.get_response(...), async for r in agent.invoke(...)). Sync wrappers do not exist. The integration must handle async span lifecycle correctly.

Tool call tracing: When ChatCompletionAgent uses plugins (tools), intermediate messages contain FunctionCallContent (the tool invocation) and FunctionResultContent (the result). These should be captured as child spans. SK v1.43 exposes an on_intermediate_message callback in invoke() / invoke_stream() for exactly this purpose.

Provider-agnostic: Semantic Kernel supports OpenAI, Azure OpenAI, Anthropic, Google, HuggingFace, and others via service connectors. The integration should capture the service type and model in span metadata, independent of which provider is configured.

Thread state: ChatHistoryAgentThread holds conversation history across invoke() calls. The integration should capture thread/conversation context in span metadata where available.

Patching approach: Patching ChatCompletionAgent.get_response, ChatCompletionAgent.invoke, and ChatCompletionAgent.invoke_stream covers the primary user-facing surface. Kernel.invoke and Kernel.invoke_prompt cover direct prompt execution without an agent wrapper.

Version gate: SK has a high release cadence (~1 release per week). The matrix should include the current latest pin and at least one older version (e.g. 1.32.0 from 2025) to ensure version compatibility.

No coverage in any instrumentation layer

  • No integration directory (py/src/braintrust/integrations/semantic_kernel/)
  • No wrapper function (e.g. wrap_semantic_kernel())
  • No patcher in any existing integration
  • No nox test session (test_semantic_kernel)
  • No version entry in py/src/braintrust/integrations/versioning.py
  • No mention in py/src/braintrust/integrations/__init__.py

A grep for semantic_kernel or semantic-kernel across py/src/braintrust/ returns zero matches.

Relationship to existing work

Issue #197 tracks the agent-framework package — Microsoft's next-generation successor to Semantic Kernel. These are different PyPI packages:

Semantic Kernel remains widely deployed in enterprise Python AI applications independently of the newer Agent Framework. Both gaps warrant separate integrations.

Braintrust docs status

not_found — Semantic Kernel is not listed on the Braintrust integrations directory or the tracing guide. There is no auto_instrument() reference, no wrap_semantic_kernel() function, and no Semantic Kernel setup documentation anywhere in Braintrust docs.

Upstream references

Local repo files inspected

  • py/src/braintrust/integrations/ — no semantic_kernel/ directory exists on main
  • py/src/braintrust/wrappers/ — no Semantic Kernel wrapper
  • py/noxfile.py — no test_semantic_kernel session
  • py/pyproject.toml [tool.braintrust.matrix] — no semantic-kernel entry
  • py/src/braintrust/integrations/__init__.py — Semantic Kernel not listed
  • py/src/braintrust/integrations/versioning.py — no Semantic Kernel version matrix
  • Full repo grep for semantic_kernel, semantic-kernel across py/src/braintrust/ — zero matches

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions