Agentica AI Function Calling Framework

repository·main·Indexed 21 days ago

https://github.com/wrtnlabs/agentica

An AI library specialized in LLM Function Calling that transforms TypeScript classes, Swagger/OpenAPI documents, and MCP servers into stable AI agents. It features compiler-driven development to automate schema construction, JSON schema conversion across different LLM vendors, a validation feedback strategy to correct AI argument errors, and a selector agent to optimize token consumption.

Tokens
123.3K
Snippets
295
Records
402
Agent score
76%

What's inside Agentica

  1. Overview of Wrtn OS

    main

    Wrtn OS is a service platform designed for both AI agent creators and developers. It provides an ecosystem for creating, monetizing, and benchmarking AI agents.

    For Customers (Agent Creators)

    • No-code Agent Creation: Build AI agents without writing code.
    • OpenAPI Marketplace: Purchase OpenAPI documents to provide specific functions to your agents.
    • Prompt Engineering: Write guide prompts to define agent behavior.
    • Benchmarking: Use built-in tools to measure and evaluate AI agent performance.

    For Developers

    • Monetization: Supply OpenAPI documents to the marketplace, allowing customers to purchase them as functional capabilities for their agents.
  2. What is Agentica

    main

    Agentica is an AI Function Calling framework designed to simplify the creation of Agentic AI. Instead of building complex agent graphs or manual workflows, you provide Agentica with Swagger/OpenAPI/MCP documents or TypeScript class types. Agentica then automatically handles the function calling logic using an LLM.

    Key capabilities include:

    • Automatically calling backend APIs or TypeScript functions via LLM function calling.
    • Enabling users to perform complex tasks (like searching and purchasing products) through natural conversation.
    • Supporting various integration formats like OpenAPI and MCP.
  3. What is Document Driven Development in Agentica

    main

    Document Driven Development (DDD) is a paradigm for AI agent development that shifts focus from drawing complex agent workflow graphs to writing high-quality documentation (comments) for individual functions.

    In traditional agent development, adding nodes to a workflow graph increases complexity and decreases the overall success rate due to the Cartesian product of individual node success rates. In Document Driven Development, you delegate responsibility to LLM function calling. By concentrating on the documentation of each function independently, the success rate of each function remains independent, allowing for more flexible, scalable, and reliable agent development. This approach is designed to work in tandem with Compiler Driven Development.

  4. What is Compiler Driven Development in Agentica

    main

    In Agentica, Compiler Driven Development is the principle that LLM (Large Language Model) function calling schemas must be constructed by a compiler rather than written by hand.

    Manual schema creation is error-prone; while a human frontend developer might intuitively catch a mistake in API documentation, an AI will fail to execute function calls if the schema is incorrect. To ensure stability and efficiency, Agentica relies on compilers to automatically generate these schemas from source code (like TypeScript classes or backend framework definitions) to eliminate code duplication and human error.

  5. What is MicroAgentica and when to use it

    main

    MicroAgentica is a lightweight facade class for a micro AI agent, designed for small-scale applications.

    Key Differences from Agentica:

    • Orchestration: It lacks a selector agent. It only uses caller and describer agents. The caller agent is directly provided with a list of every available function.
    • Performance: Because it skips the selector step, it is faster than the full Agentica implementation.
    • Use Case:
      • Use MicroAgentica if your application has fewer than 8 functions.
      • Use Agentica if you have more than 8 functions, as the full orchestration helps prevent the AI from becoming confused and maintains function-calling performance.
  6. What is LLM Function Calling in Agentica

    main

    Agentica is an Agentic AI framework specialized in LLM Function Calling.

    In this context, Function Calling refers to the process where a Large Language Model (LLM) selects an appropriate function from a provided list and populates its arguments by analyzing the conversation context. This is closely related to structured output, where the LLM transforms conversational text into structured JSON data.

    By providing a list of candidate functions to @agentica, you can build agentic AI capabilities that automatically interact with your tools and services.

  7. Upcoming Support for Local LLMs via Prompt Templates

    main
    Agentica is working towards supporting Local LLMs that lack native function calling capabilities. This will be achieved by implementing specialized function calling prompt templates and validating the arguments composed by the LLM. This allows smaller models (e.g., 8b or 3b parameters) to perform complex agentic tasks, such as managing hundreds of functions, even on high-spec laptops or directly in a web browser.
  8. Prioritize Validation Feedback Over JSON Schema

    main

    In Agentica, Validation Feedback always overrides the JSON Schema. The schema defines the general structure, but the validation feedback reflects the actual runtime state, which is often a strict subset of the schema.

    Rules for handling conflicts:

    • If the schema allows a string but expected lists 5 specific values, use only those 5 values.
    • If a schema enum has 8 items but expected shows only 2, use only those 2 (the others are considered consumed).
    • If a schema union includes a type but feedback says it is banned, never retry that type.
    • If feedback indicates items are already loaded, stop requesting them; they are already in the conversation history.
  9. Understand the Validation Error Structure

    main

    When function calling fails, Agentica provides an IValidation.IError object to help correct the arguments. This object contains specific details about why a value was rejected.

    Key fields in IValidation.IError:

    • path: The exact JSON path to the error (e.g., "$input.user.email").
    • expected: The values or types that are actually valid in the current runtime state. This is critical because it may be stricter than the original JSON schema (e.g., an enum might have been partially consumed).
    • value: The rejected value that caused the failure.
    • description: Authoritative, binding instructions. If this field is present, you must follow it exactly (e.g., instructions on available items or banned types).
    interface IValidation.IError {
      path: string;         // Location: "$input.user.email"
      expected: string;     // Values/types actually valid in current runtime state
      value: unknown;       // Your value that failed
      description?: string; // Authoritative instructions — follow exactly when present
    }
  10. Customize the Orchestration Executor

    main

    The IAgenticaExecutor configuration allows you to modify how internal sub-agents handle orchestration during Agentica.conversate().

    • initialize: If set to null, the agent skips the initialization process and moves directly to the selection process.
    • select: This property determines which functions are candidates for calling. For large numbers of controller functions, it is highly recommended to use a strategy like PG Vector Selector to select only relevant functions. This significantly reduces LLM token consumption compared to passing all functions in every request.
    const agent = new Agentica({
      // ... other props
      config: {
        executor: {
          initialize: null,
          select: AgenticaPgVectorSelector.boot(
            "https://your-connector-hive-server.com",
          ),
        },
      },
    });
  11. Comparison of API documentation methods in Java Spring, PHP Laravel, and Python

    main

    The article discusses the challenges of maintaining accurate API documentation (Swagger/OpenAPI) across different backend ecosystems, which is critical for 'Super AI Chatbot' (LLM function calling) development.

    • Java Spring (Spring RestDocs): Requires manual writing of API endpoints and schema types within test code. Errors are only caught at runtime, not during compilation.
    • PHP Laravel (Swagger annotations): Uses @OA tags in docblocks. This is highly error-prone as typos in annotations (e.g., @QA Property) are not caught by the compiler or language runtime, leading to unreliable documentation.
    • Python Django (DRF-Spectacular): Similar to Spring, it requires manual use of decorators like @extend_schema to define request/response schemas, which is prone to human error.
    • Python FastAPI: Considered the ideal paradigm for the AI era because it automatically generates OpenAPI documentation by parsing Python type hints and field descriptions, reducing manual documentation overhead.
  12. Capabilities of the Notion Agent

    main

    The Notion Agent uses natural language to trigger specific functions within the NotionService. Common capabilities include:

    • Retrieve a List of Pages: Uses readPageList to find pages.
    • Read Page Contents: Uses readPageContents to fetch details.
    • Create New Pages: Uses createPageByMarkdown to format and create pages.
    • Update Existing Pages: Uses updatePageContent to modify content.

    Example interaction: "Summarize the latest meeting discussion and create a new page with the summary."