Use LangChain agents in h2oGPT for web search, Python execution, CSV analysis, AutoGPT, and multi-agent workflows.
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.
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.
h2oGPT exposes an OpenAI-compatible proxy server on a separate port. Agents with the highest quality run against this endpoint.
import openaiclient = 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.
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",)