Skip to main content
Semantic Kernel’s planner executes multi-step reasoning chains autonomously. Each step is an LLM call with its own prompt, context window, and potential for prompt injection, PII leakage, or runaway function invocation. Without observability at the call level, you cannot tell whether your SK agent is behaving as designed, being manipulated, or silently accruing cost. Cognisafe intercepts every ChatCompletion call that SK makes — including planner steps, plugin-routed function calls, and memory retrievals that go through an LLM re-ranker. Because Cognisafe presents an OpenAI-compatible proxy endpoint, SK requires zero code changes beyond setting the base URL.

What gets captured

Architecture

Python implementation

1

Install dependencies

2

Configure Cognisafe and patch OpenAI

Call cognisafe.configure and cognisafe.patch_openai before constructing the SK kernel. The patch rewrites the OpenAI client’s base_url — SK’s OpenAIChatCompletion connector inherits this automatically.
3

Add plugins and invoke the planner

Plugins and function invocations are captured as part of the LLM calls that SK makes to orchestrate them. The arguments and results are visible in request_body and response_body in the Cognisafe dashboard.

.NET / C# implementation

SK for .NET uses HttpClient under the hood. Configure the proxy base URL on the HttpClient that the kernel’s OpenAI connector uses.
1

Install packages

2

Configure the kernel with Cognisafe proxy

3

Invoke with execution settings

Plugin and function call security

SK’s function-calling loop can invoke plugins repeatedly within a single plan. Each LLM call that includes function invocation instructions is logged separately. In the Cognisafe dashboard, filter by agent_name = "customer-support-agent" to see the full invocation chain for a single user request. To detect dangerous function call patterns, configure a custom scorer in evals/scorers.yaml:
This scorer runs on every SK LLM call and fires a threat_detected webhook if any of the listed function names appear in the tool call arguments.

Planner patterns and observability

SequentialPlanner generates a complete plan before execution. In Cognisafe, you will see:
  1. One LLM call for plan generation (typically a large request_body containing the goal and available plugin descriptions).
  2. One LLM call per plan step during execution.
StepwisePlanner (ReAct-style) generates one reasoning step at a time. You will see a sequence of short-cycle calls, each containing the intermediate scratchpad. This makes it easy to identify loops, backtracking, or hallucinated tool names. Filter requests by model and agent_name in the dashboard and sort by created_at to reconstruct the full reasoning chain for any agent execution.

Semantic Memory (embeddings)

When SK calls a vector store to retrieve memories, the embedding generation call goes through the patched OpenAI client and is therefore logged. The model field will be text-embedding-3-small (or whichever embedding model you configure). These calls are low-cost but high-frequency — use the Cognisafe cost dashboard to track embedding spend separately from completion spend.
Filter the Cognisafe requests view by model LIKE 'text-embedding%' to isolate memory retrieval activity from planning and completion calls.

Agent tagging

Set kernel.name in Python or kernel.Data["agent_name"] in .NET before any invocation. Cognisafe reads the X-Cognisafe-Agent-Name header (injected by the SDK) and writes it to llm_requests.agent_name. All dashboard groupings, alert rules, and cost breakdowns are keyed on this field. For multi-agent systems (e.g. an orchestrator kernel that spawns specialist sub-kernels), use distinct names:
Each sub-kernel’s calls appear as a separate series in the Cognisafe agent breakdown view. Configure these in the Cognisafe alerting UI or via the API:

Azure deployment

For production SK agents on Azure, deploy within the same AKS cluster as Cognisafe so all traffic stays within the VNet:
The proxy forwards to Azure OpenAI via the private endpoint configured in the Azure OpenAI + APIM pattern.
Semantic Kernel’s FunctionChoiceBehavior.Auto in .NET 1.x will retry failed function calls silently. Each retry is a separate LLM call and will appear as a separate row in Cognisafe. If you see unexpectedly high call counts for an agent, check for retry loops in the planner execution trace.