Use tool calling and MCP servers with LLMs

Enable LLMs to call functions and tools, then execute the results automatically.

Agents · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

How it works

You define tools with JSON schemas, pass them to the LLM, and use invoke_tools to execute the function calls.

What it covers

  • Define tools as Python functions
  • Let LLMs decide which tool to call
  • Automatically execute tool calls with invoke_tools
  • Use MCP servers to load external tools

What it uses

Install
terminal
pip install pixeltable openai mcp
Environment variables it names
OPENAI_API_KEY
Pixeltable calls
openai.chat_completions()openai.invoke_tools()@pxt.udfpxt.tools()pxt.create_table()pxt.mcp_udfs()add_computed_column()insert()

A look at the code

llm-tool-calling.ipynb
# Add LLM call with tools
queries.add_computed_column(
response=openai.chat_completions(
messages=[{'role': 'user', 'content': queries.query}],
model='gpt-4o-mini',
tools=tools, # Pass tools to the LLM
)
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103
  • Agentic Patterns

    Build the six architectural patterns of agentic AI (prompt chaining, routing, parallelization, tool use, evaluator-optimizer, orchestrator-worker) and the ReAct and planning strategies as Pixeltable tables and computed columns.

    Updated Open in Colab
  • LLM as judge

    Score model output with a second model, as a chain of computed columns

    Recipe · Updated
  • Document Indexing and RAG

    In this tutorial, we'll demonstrate how RAG operations can be implemented in Pixeltable. In particular, we'll develop a RAG application that summarizes a collection of PDF documents and uses ChatGPT to answer questions about them.

    Updated Open in Colab