A native function is conventionally programmed code that an orchestration framework or language-model application can invoke to perform an action, such as reading a file, scraping a website, searching the web, or calling an API. Semantic Kernel can register native functions as plugins or skills, making them available to chat and agent interfaces. section 5.4 section 5.8
A typical native-function workflow is:
- Define the operation in code, commonly inside a class or Python function. section 5.4.2 section 7.5
- Describe and expose the function through the framework’s registration mechanism, such as Semantic Kernel’s kernel function decorator or Nexus’s agent_action decorator. section 5.4.2 section 7.5
- Invoke it directly or let an agent select it through a generated tool specification and function-calling interface. section 7.5
- Pass its result into a semantic function when code supplies information that an LLM should interpret. section 5.4.3
Movie-history lookup
A MySeenMoviesDatabase native function reads seen_movies.txt, strips each line, joins the titles, and returns them as a comma-separated string. Semantic Kernel registers it as SeenMoviesPlugin; a movie-recommendation semantic function then uses {{MySeenMoviesDatabase.LoadSeenMovies}} to recommend an unseen film. section 5.4.2 section 5.4.3
Listing 5.14 SK_native_functions.py (MySeenMovieDatabase)
class MySeenMoviesDatabase:
"""
Description: Manages the list of users seen movies. #1
"""
@kernel_function( #2
description="Loads a list of movies … user has already seen",
name="LoadSeenMovies",
)
def load_seen_movies(self) -> str: #3
try:
with open("seen_movies.txt", 'r') as file: #4
lines = [line.strip() for line in file.readlines()]
comma_separated_string = ', '.join(lines)
return comma_separated_string
except Exception as e:
print(f"Error reading file: {e}")
return None
Inspect the complete file-backed implementation, including the kernel function metadata, file read, formatting, and error handling. section 5.4.2
