liveBook · Manning

Native function

As explained in AI Agents in Action

A native function is a conventionally programmed function that can be invoked by an orchestration framework or language-model application.

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

How AI Agents in Action covers it

How deep it goes
Explains definitions, registration, direct invocation, composition, tool specifications, and execution, while deferring memory details.
Examples
Uses a movie-history file reader, movie recommendation, weather action, web APIs, and parallel tool calls.
What it assumes
Assumes basic Python and function concepts while introducing agent actions, plugins, skills, and semantic-function composition.
What you can do after
Build native actions, register them as plugins or tools, compose them with semantic functions, and execute agent-selected calls.
How it connects
Connects native functions with semantic functions, plugins, skills, function calling, tools, APIs, and agent systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action. The section links point to the parts of the book it draws on.