Integrations / Semantic Kernel
To trace Semantic Kernel with Tracify in Python, wrap the invocation with trace_agent and open a step around the kernel function or agent call. Plugins you mark show up as steps in order.
Your code
Semantic Kernel
Tracify
One run.
Setup
The Python flavor of Semantic Kernel and the Tracify SDK.
pip install tracify-sdk semantic-kernelCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."Semantic Kernel is async. trace_agent and span both work in async functions.
import tracify
@tracify.trace_agent(name="sk-assistant")
async def ask(question: str) -> str:
with tracify.span("kernel-invoke", type="agent", input=question) as step:
result = await kernel.invoke(plugin_name="chat", function_name="answer", question=question)
step.set_output(str(result))
return str(result)A kernel function decorator is the best place for a step, because every call through it is then recorded wherever it comes from.
from semantic_kernel.functions import kernel_function
class OrdersPlugin:
@kernel_function(description="Look up an order by id")
async def lookup(self, order_id: str) -> str:
with tracify.span("orders.lookup", type="tool", input=order_id) as step:
status = await orders_api.status(order_id)
step.set_output(status)
return statusRun your code one time, then open the Tracing page of your project. Your kernel call shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The Tracify SDKs are available for Python and TypeScript. For Semantic Kernel in .NET or Java, you can send traces to the Tracify API directly.
Good to know
Semantic Kernel calls models through its own connectors, so those requests are not wrapped automatically. Mark the function that makes them and you get its timing and output.
Full details in the documentation. All integrations are listed on the integrations page.
