Wildcard provides seamless integration with OpenAI’s models through the WildcardClient class. This integration allows you to use OpenAI’s function calling capabilities with Wildcard’s tool selection and execution system.

Architecture Overview

Wildcard OpenAI Architecture
The integration follows a structured flow:
  1. Your User Message: The starting point - a natural language request from your user.
  2. Wildcard Integrations: The system loads and prepares the relevant API tools based on your configuration.
  3. OpenAI Tool Calling: OpenAI’s model processes the user request and selects the appropriate tools to use.
  4. Wildcard Post-Processing: After tool execution, Wildcard processes the API responses into a standardized format.
  5. Response Components:
    • Context Optimized Response: A formatted response optimized for the LLM’s context window
    • Documents: Any attachments or binary data from the API response
  6. Document Flow:
    • Documents are sent to your RAG Document Store for long-term storage
    • The Context Optimized Response is sent to the LLM Context
This architecture provides several key benefits:
  • Efficient tool selection and execution
  • Proper handling of API responses
  • Optimal context management for LLMs
  • Integration with your RAG system

Tool Formats

Wildcard supports tool formats that can be used for different purposes in your application.

OpenAI Format

The OpenAI format converts tools into OpenAI’s function schema format, which is required for function calling capabilities: The OpenAI format is used when you need a tool to be used in the tools array of an OpenAI completion.
tool_name = Action.Gmail.MESSAGES_SEND
await client.get_tool(tool_name, format=ToolFormat.OPENAI)

Wildcard Format

The Wildcard format is an enriched version of the tool defintion.
tool_name = Action.Gmail.MESSAGES_SEND
await client.get_tool(tool_name, format=ToolFormat.WILDCARD)

Wildcard Prompt

The Wildcard Prompt is used when you need to describe available tools to the LLM. This improves the LLM’s ability to understand the tools and use them effectively.
tool_name = Action.Gmail.MESSAGES_SEND
prompt = await client.get_tool_prompt(tool_name=Action.Gmail.MESSAGES_SEND)
system_prompt = {"role": "system", "content": prompt}

Response Processing

See Processed Response for schema details.
Integrations includes built-in response processing that:
  • Formats API responses for optimal context
  • Extracts and manages documents
  • Provides structured data for your RAG system
  • Handles large responses

Example Usage

Here’s a complete example showing the architecture in action:
from wildcard_openai import WildcardClient
from openai import AsyncOpenAI
from wildcard_core.models import APIService
from wildcard_openai.WildcardClient import ToolFormat
from wildcard_core.client import ProcessedResponse, ProcessedResponseData   

async def run(user_message: str):
    # Initialize clients
    wildcard = WildcardClient(
        api_key="your_wildcard_api_key",
        index_name="your_index_name"
    )
    openai = AsyncOpenAI(api_key="your_openai_api_key")

    # 1. Configure API integrations - see Authentication docs
    wildcard.register_api_auth(
        APIService.GMAIL,
        {"client_id": "...", "client_secret": "..."}
    )

    # 2. Add tools to the client
    wildcard.add_tool_by_api_service(APIService.GMAIL)

    # 3. Get tools in OpenAI format
    tools = [wildcard.get_tool(Action.Gmail.MESSAGES_SEND, format=ToolFormat.OPENAI)]

    # 4. Run OpenAI completion with tool calling
    completion = await openai.chat.completions.create(
        model="gpt-4o",
        messages=[{
            "role": "user",
            "content": user_message
        }],
        tools=tools,
        tool_choice="auto"
    )

    # 5. Execute tool calls and process response
    result: ProcessedResponse = await wildcard.run_tools(completion)

    # 6. Access different response components
    context: ProcessedResponseData = result.processed_response.data  # Context optimized response
    documents = result.processed_response.documents  # Any documents/attachments

    return context, documents

Next Steps