ambitious-oil-42507
10/16/2025, 10:53 AMtall-airline-16756
10/16/2025, 10:53 AMtall-airline-16756
10/16/2025, 10:54 AMgpt-4.1-mini as the LLM. Just follow these simple steps:
1. Define a Web Search Tool: Start by creating a function for web search using a tool like DuckDuckGo. Here's an example to get you started:
@function_tool
async def search_web(ctx: RunContext[AppData], query: str):
ddgs_client = ctx.userdata.ddgs_client
search = await asyncio.to_thread(ddgs_client.text, query)
if len(search) == 0:
raise ToolError("No results found.")
return search
1. Initialize the Agent: Next, add the search tool to your agent's configuration like this:
agent = Agent(instructions="You are a helpful assistant.", tools=[search_web])
1. Set the LLM: Then, make sure to use gpt-4.1-mini in your agent session:
session = AgentSession(
llm=openai.LLM(model="gpt-4.1-mini"),
userdata=app_data
)
1. Ensure Dependencies: Finally, don't forget to install the necessary packages like duckduckgo-search, livekit-agents, and the OpenAI plugin. Also, initialize the DuckDuckGo client within your app data.
This setup will allow your agent to perform web searches whenever needed. If you have any questions or need a hand with any step, just let me know—I’m here to help!
Sources: examples/voice_agents/basic_agent.py | Large language models (LLM) | LiveKit Docs | basics/say_in_voice.pyambitious-oil-42507
10/16/2025, 10:55 AMtall-airline-16756
10/16/2025, 10:55 AMgpt-4.1-mini model doesn’t come with a built-in web search tool in LiveKit. But no worries! You can add web search functionality by creating a custom function_tool that connects with an external search service like DuckDuckGo or another API.
If you'd like, I’m here to help walk you through the setup or share some examples—just let me know!
Sources: OpenAI LLM models | LiveKit Docs | plugins/openai/src/models.ts | Build voice, video, and physical AI | LiveKit | Large language models (LLM) | LiveKit Docs | examples/voice_agents/realtime_joke_teller.pyambitious-oil-42507
10/16/2025, 10:56 AMtall-airline-16756
10/16/2025, 10:57 AMmax_results and search_prompt to suit your needs. The speed can vary depending on things like network latency and how quickly the search provider responds, so trying out both could really help you find what works best for you.
About gpt-4.1-mini, just a heads-up that using it via a plugin doesn’t come with built-in web search capabilities. You’d still need to set up web search as a custom tool or plugin alongside the language model.
If you’d like, I’m here to help guide you through implementing either option—just let me know!
Sources: OpenAI and LiveKit | LiveKit Docs | examples/voice_agents/requirements.txt | Large language models (LLM) | LiveKit Docsambitious-oil-42507
10/16/2025, 10:59 AMtall-airline-16756
10/16/2025, 11:00 AMaiohttp.
3. Finally, parse the API response and send back the relevant results to your agent.
If you’d like, I’d be happy to walk you through a detailed example of how to add Bing Search to your LiveKit agent. Just let me know—I’m here to help!
Sources: examples/voice_agents/background_audio.py | tooling/api-documenter/src/documenters/OfficeYamlDocumenter.tsambitious-oil-42507
10/16/2025, 11:01 AMtall-airline-16756
10/16/2025, 11:01 AMaiohttp installed to handle HTTP requests smoothly. You can easily install it by running:
pip install aiohttp
1. Create a Custom Function Tool: Now, let’s define a tool that performs web searches using the Bing API. Here’s an example to guide you:
from livekit.agents import function_tool, ToolError
import aiohttp
@function_tool
async def search_web_with_bing(ctx, query: str):
"""
Perform a web search using Bing Search API.
Args:
query: The search query string.
"""
bing_url = "https://api.bing.microsoft.com/v7.0/search"
headers = {"Ocp-Apim-Subscription-Key": "your-api-key"}
params = {"q": query, "count": 5}
async with aiohttp.ClientSession() as session:
async with session.get(bing_url, headers=headers, params=params) as resp:
if resp.status != 200:
raise ToolError("Bing search failed with status code: {}".format(resp.status))
result = await resp.json()
# Extract relevant data (e.g., webPages.value)
return result.get("webPages", {}).get("value", [])
1. Integrate the Tool into Your Agent: Next, add this custom tool to your agent configuration so your agent knows how to use it:
from livekit.agents import Agent
agent = Agent(
instructions="You are a helpful assistant.",
tools=[search_web_with_bing]
)
1. Start the Agent Session: Finally, use the AgentSession to initialize your agent with the LLM and the custom tool you just created:
from livekit.plugins import openai
from livekit.agents import AgentSession
session = AgentSession(
llm=openai.LLM(model="gpt-4.1-mini"),
userdata={}
)
await session.start(agent=agent)
This setup will empower your agent to perform web searches using Bing seamlessly. Just remember to replace "your-api-key" with your actual Bing API key. If you have any questions or need a hand with any part of this, please don’t hesitate to reach out—I’m here to help!ambitious-oil-42507
10/16/2025, 11:04 AMtall-airline-16756
10/16/2025, 11:05 AM# Define tools externally
tools = [weather_tool, calendar_tool]
agent = Agent(
instructions="You are a helpful assistant",
tools=tools
)
• Define tools inside the Agent class: This works nicely if the tools are unique to that specific agent or if you like keeping related features bundled together. Here's how that might look:
class MyAgent(Agent):
@function_tool
def get_weather(self, location: str) -> str:
return f"Weather in {location} is sunny"
For bigger projects, defining tools outside the Agent class usually gives you more flexibility and makes your code easier to reuse. If anything’s unclear or you want to dive deeper, just let me know—I’m here to help!
Sources: Tool definition and use | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs