Skip to main content
h2oGPT integrates several LangChain agent types that extend the LLM with tools for search, code execution, data analysis, and autonomous task planning. Agents work best with OpenAI models; some agent types are limited to OpenAI due to their reliance on function tool calling.

Available agent types

Search

Web search agent. Works with non-OpenAI models after h2oGPT improvements beyond base LangChain.

Python

Executes Python code. Currently only supported with OpenAI models.

CSV

Analyzes CSV files. Works well with OpenAI due to function tool calling support.

JSON

Queries and navigates JSON data. Alpha quality; currently requires OpenAI.

AutoGPT

Autonomous goal-directed agent. Alpha quality. Supports a broad tool suite.

AutoGen

Multi-agent code execution framework via the OpenAI proxy server.
The Collection and Pandas agents are disabled or pre-alpha. Do not rely on them in production.

AutoGPT tools

When you enable the AutoGPT agent, it has access to the following tools:
  • Search — web search via SerpAPI or DuckDuckGo
  • Wikipedia — direct Wikipedia lookups
  • Shell — run shell commands
  • File — read and write files
  • Python — execute Python code
  • Requests — make HTTP requests
  • Wolfram Alpha — computational queries
AutoGPT also maintains a memory across tool calls within a session.

Enabling agents in the UI

1

Install agent dependencies

pip install -r reqs_optional/requirements_optional_agents.txt
2

Set your SerpAPI key (optional)

If you want web search, export your SerpAPI key before starting h2oGPT:
export SERPAPI_API_KEY=your_key_here
Without this key, web search falls back to DuckDuckGo.
3

Start h2oGPT

python generate.py --base_model=gpt-3.5-turbo
4

Select an agent in the UI

Open the Resources panel in the Gradio UI. Under Agents, select the agent type you want to use (e.g., Search, CSV). The Search agent also appears as a standalone option under Resources.

Code-first agents via the OpenAI proxy

h2oGPT exposes an OpenAI-compatible proxy server on a separate port. Agents with the highest quality run against this endpoint.
import openai

client = openai.OpenAI(
    base_url="http://localhost:5001/v1",  # h2oGPT OpenAI proxy port
    api_key="EMPTY",
)

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Search the web for the latest h2oGPT release."}],
)
print(response.choices[0].message.content)
See openai_server/openai_client.py in the h2oGPT repo for a full code-first agent example that generates plots, researches topics, and evaluates images via a vision model.

Function tool calling

h2oGPT supports OpenAI-compatible function tool calling with auto tool selection. This powers the CSV and JSON agents and lets you define custom tools:
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a city.",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "What is the weather in Austin?"}],
    tools=tools,
    tool_choice="auto",
)

AutoGen multi-agent

AutoGen enables multi-agent code execution workflows. h2oGPT acts as the backend LLM via the OpenAI proxy:
1

Install AutoGen

pip install pyautogen
2

Point AutoGen at the h2oGPT proxy

import autogen

config_list = [
    {
        "model": "h2ogpt",
        "base_url": "http://localhost:5001/v1",
        "api_key": "EMPTY",
    }
]

assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config={"config_list": config_list},
)

user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    code_execution_config={"work_dir": "coding"},
)

user_proxy.initiate_chat(
    assistant,
    message="Write a Python script to fetch and plot BTC prices for the last 7 days.",
)
AutoGen code execution runs shell commands and Python on the host machine. Run it in an isolated environment or Docker container.

Build docs developers (and LLMs) love