Inferensys

Glossary

Semantic Functions

Semantic functions are templated natural language prompts that are registered and invoked as callable functions within AI frameworks, enabling large language models to orchestrate native code and external tools.
Governance lead reviewing model governance framework on laptop, policy documents visible, executive office setup.
FUNCTION CALLING FRAMEWORKS

What is Semantic Functions?

A core concept in agentic AI frameworks where natural language instructions are templated and invoked as executable functions.

A semantic function is a templated natural language prompt—such as an instruction, question, or few-shot example—that is packaged and invoked as a callable software function within an AI orchestration framework like Semantic Kernel. Unlike a traditional function written in code, its core logic is a parameterized prompt executed by a large language model (LLM). This abstraction allows developers to treat complex natural language reasoning tasks as modular, composable units within a conventional program, bridging the gap between symbolic code and neural network inference.

Semantic functions often serve as the orchestration layer that plans and sequences calls to native plugin functions (tools that execute code or API calls). By dynamically composing their prompts with context and variables, they enable multi-step workflows where an LLM's reasoning directs external actions. This pattern is foundational to building AI agents that can decompose high-level goals into executable plans, integrating prompt engineering directly into application architecture for tasks like planning, summarization, and conditional logic.

SEMANTIC KERNEL

Core Components of a Semantic Function

In frameworks like Semantic Kernel, a semantic function is a templated, callable unit that encapsulates a natural language prompt and orchestrates interactions between native code and large language models.

01

Prompt Template

The core of a semantic function is a prompt template—a parameterized string of natural language instructions and few-shot examples. This template is dynamically rendered at runtime using a template engine that injects variables from the execution context.

  • Variables: Placeholders like {{$input}} or {{$skillName}} are replaced with actual values.
  • Few-Shot Examples: In-context learning examples embedded in the template guide the model's output format.
  • Engine: Uses a syntax (e.g., Handlebars) to separate logic from the prompt text, enabling reuse and composition.
02

Execution Configuration

This component defines the runtime parameters for the large language model call. It is separate from the prompt logic and controls the deterministic aspects of the inference.

  • Model Selection: Specifies which LLM (e.g., GPT-4, Claude 3) to use for completion.
  • Inference Parameters: Sets values for temperature, top_p, max_tokens, and stop sequences to control creativity and length.
  • Service Endpoint: Configures the API endpoint and authentication, allowing the same function to target different model providers or deployments.
03

Native Function Orchestration

A defining feature is the ability to invoke native plugin functions (code written in C#, Python, etc.). The semantic function acts as a planner or orchestrator, using the LLM to decide when and how to call these functions.

  • Skill/Plugin Reference: The function has access to a registry of available native functions (skills).
  • Parameter Marshaling: The LLM's natural language output is parsed to generate structured inputs for the native function call.
  • Chaining: Outputs from native functions can be fed back into the semantic function's context for multi-step reasoning.
04

Input/Output Schema

While flexible, semantic functions often define expected input parameters and return types to integrate cleanly within a larger, typed application. This provides a contract for developers.

  • Parameter Definition: Describes the variables the prompt template expects (e.g., topic: string, tone: enum).
  • Structured Output: Though the core output is text, post-processing can enforce a JSON Schema or a Pydantic model to guarantee a structured response for downstream systems.
  • Context Variable Binding: Inputs are bound to the function's execution context, making them available to the template engine.
05

Skill/Plugin Context

The semantic function executes within a runtime context that provides access to shared services, memory, and, crucially, other functions. This context enables composition and statefulness.

  • Skill Collection: A reference to the set of native and semantic skills the function can invoke.
  • Memory Connectors: Access to vector stores or other memory systems for retrieval-augmented generation (RAG) within the prompt.
  • Conversation History: The context maintains the dialog history, allowing the function to be aware of previous interactions.
06

Planner Integration

In advanced use, semantic functions are used by planners—specialized components that automatically chain functions together to achieve a complex goal. The function's description and schema are metadata for the planner.

  • Goal Decomposition: A planner (e.g., a Sequential Planner) uses a semantic function to break a user request into a plan of actionable steps.
  • Auto-Generated Plans: The planner LLM reads the descriptions of available semantic functions to construct a valid execution sequence.
  • Orchestration: The planner handles the execution flow, error handling, and passing results between functions in the chain.
FUNCTION CALLING FRAMEWORKS

How Semantic Functions Work

Semantic functions are a core abstraction in frameworks like Semantic Kernel that package natural language prompts as callable, composable units within an AI agent's workflow.

A semantic function is a templated natural language instruction, defined as a prompt with typed input parameters, that is invoked programmatically like a traditional software function. Unlike native plugin functions that execute code, a semantic function's body is a prompt template; when called, it is sent to a large language model (LLM) for completion. This abstraction allows developers to treat complex reasoning or text-generation tasks as modular, reusable components that can be orchestrated by planners and chained with native functions.

The execution flow involves the framework injecting the provided arguments into the prompt template and sending the fully rendered prompt to the configured LLM. The model's text output is then returned as the function's result. Crucially, semantic functions can be composed into plans, where a planner AI dynamically sequences them with native tools to achieve a complex goal. This enables the creation of flexible, prompt-driven workflows where the logic is partly defined in natural language and partly in code.

SEMANTIC FUNCTIONS

Frequently Asked Questions

Semantic functions are a core abstraction in frameworks like Semantic Kernel, templating natural language prompts into callable functions that can orchestrate native code. This FAQ addresses their role in AI agent tool calling.

A semantic function is a templated natural language prompt, defined within a framework like Semantic Kernel, that is invoked as a callable function within an AI agent's execution plan. It works by taking a predefined prompt template—which can include variables, few-shot examples, and specific instructions—and executing it through a configured large language model (LLM). The model's generated text output is then returned as the function's result. Unlike native plugin functions written in code (e.g., Python or C#), a semantic function's logic is defined by its prompt and the LLM's reasoning capabilities. It acts as a bridge between high-level intent and actionable steps, often orchestrating calls to other native functions based on the LLM's structured reasoning.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.