How to Build a Real-Time Browser Agent with GLM-5-Turbo
By Braincuber Team
Published on April 20, 2026
GLM-5-Turbo is designed specifically for agent-style workflows, where the model coordinates multi-step execution. It is optimized for understanding complex instructions, invoking tools reliably, and producing structured outputs that can be consumed by systems.
What You will Learn:
- Understanding GLM-5-Turbo and agent workflows
- Setting up the LLM client with Z.AI or OpenRouter
- Defining browser tools for web interaction
- Building the agent loop for multi-step execution
- Extracting flight information using regex patterns
- Creating a Streamlit UI for the browser agent
- Running and testing the real-time agent
What is GLM-5-Turbo?
GLM-5-Turbo is designed to support real-world agent workflows. It provides multiple thinking modes, allowing users to balance between faster responses and deeper reasoning depending on the task.
For interactive applications, it also supports streaming output, enabling responses to be delivered token-by-token for a more responsive user experience.
One of its core strengths is function calling, which allows the model to invoke external tools reliably. The model also supports structured outputs such as JSON, making it easier to integrate with downstream systems and UI layers.
Built for Agent Workflows
GLM-5-Turbo is deeply optimized for agent-style environments, particularly scenarios like OpenClaw, where tasks involve multiple steps, tools, and long execution chains.
This optimization improves several critical areas: tool invocation reliability, instruction decomposition, and long-chain execution stability.
Build a Real-Time Browser Agent
In this tutorial, we will create a Streamlit application that behaves like a lightweight travel assistant. The user provides a query such as "Find the cheapest flights from SFO to JFK next Friday to Monday." The system will then search the web for relevant flight pages, open and inspect those pages, extract useful information such as price, duration, and stops, and summarize the best options in a user-friendly format.
LLM Layer
Sends chat-completion requests to Z.AI or OpenRouter with tool support.
Browser Tools
Exposes actions such as searching, opening pages, and extracting content.
Agent Loop
Connects the model and tools into a multi-step workflow.
Streamlit UI
Provides an interface for interaction and visualization.
Prerequisites
Install Python dependencies and set up API keys.
Before building the application, make sure you have Python 3.9+, a GLM-5-Turbo API key from Z.AI or OpenRouter, and Playwright installed for browser automation.
pip install streamlit pandas python-dotenv requests playwright
playwright install chromium
Create a .env file with your API key:
PROVIDER=zai
ZAI_API_KEY=Your Z.AI API key
ZAI_BASE_URL=https://api.z.ai/api/paas/v4/chat/completions
ZAI_MODEL=glm-5-turbo
OPENROUTER_API_KEY=Your OpenRouter API key
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1/chat/completions
OPENROUTER_MODEL=z-ai/glm-5-turbo
HEADLESS=true
MAX_STEPS=10
Set Up the LLM Client
Configure the client to work with Z.AI or OpenRouter.
class LLMClient:
def __init__(
self,
provider: str,
api_key: str,
model: str,
app_name: str = "GLM-5 Browser Agent Demo",
app_url: str = "http://localhost:8501",
) -> None:
self.provider = provider.lower().strip()
self.api_key = api_key
self.model = model
if self.provider == "zai":
self.url = os.getenv("ZAI_BASE_URL", "https://api.z.ai/api/paas/v4/chat/completions")
elif self.provider == "openrouter":
self.url = os.getenv("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1/chat/completions")
Define Browser Tools
Create tools for web search and page interaction.
Define a tool schema that the model can call. These include search_web, open_url, extract_page, extract_flight_cards, and more.
{
"type": "function",
"function": {
"name": "search_web",
"description": "Search the public web for flight result pages or travel aggregators.",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"},
"max_results": {"type": "integer", "default": 8},
},
"required": ["query"],
},
},
}
Extract Flight Information
Use regex patterns to extract price, duration, and stops.
The extract_flight_cards function uses regex patterns to detect prices, times, durations, and stops from visible page text.
money_pattern = re.compile(r"(?:$|USDs?)(d{2,5})")
time_pattern = re.compile(r"d{1,2}:d{2}s?(?:AM|PM|am|pm)?")
duration_pattern = re.compile(r"d{1,2}s?hs?d{0,2}s?m?|d{1,2}s?hrs?d{0,2}s?min?", re.I)
stop_pattern = re.compile(r"nonstop|1 stop|2 stops|3 stops", re.I)
Build the Agent Loop
Create the multi-step workflow that connects model and tools.
The BrowserAgent class sends the prompt and tool schema to the model, checks for tool calls, executes those tools, and continues until a final answer is produced.
for step in range(1, self.max_steps + 1):
assistant = self.llm.create_chat_completion(
messages=messages,
tools=TOOLS,
temperature=0.2,
max_tokens=2200,
)
if assistant.tool_calls:
result = self.tool_runner(tc.name, tc.arguments)
messages.append(assistant)
messages.append({"role": "tool", "content": result})
continue
final_content = assistant.content.strip()
if final_content:
yield {"type": "final", "step": step, "content": final_content}
return
Build Streamlit UI
Create the interactive user interface.
The Streamlit UI collects trip details from the user, launches the agent, streams intermediate steps, and renders a summary with a structured table of top flight options.
Launch the App
Run the application with: streamlit run app.py
Conclusion
In this tutorial, we built a real-time browser agent with GLM-5-Turbo, Playwright, and Streamlit. The model acts as a planner, the browser tools act as the execution layer, and the UI turns structured results into a user-friendly format.
The most important takeaway is that the value does not come from the model alone. It comes from combining the model with a controlled tool layer and an agent loop.
You can improve extraction by adding site-specific parsers, extending the system to hotels or itineraries, or integrating user preferences such as nonstop flights or preferred airlines.
Frequently Asked Questions
Do I need a GPU to run this GLM-5-Turbo project?
No. This project does not require a GPU because the model is accessed via API (Z.AI or OpenRouter). All heavy computation happens on the provider infrastructure while your local machine only handles the UI and browser automation.
Why use a browser agent instead of a flight API?
APIs are more reliable and structured, but they are limited to predefined data and often require paid access. A browser agent can explore multiple sources dynamically, adapt to different queries, and work without pre-integrated APIs.
Why does the agent sometimes fail on certain websites?
Many travel websites use dynamic JavaScript rendering, anti-bot protections, and frequently changing layouts. Since this demo relies on generic browser automation and heuristic extraction, it may not work consistently across all sites.
Why did we avoid returning JSON as the final output?
JSON is useful internally for debugging and structured processing. However, end users prefer readable summaries. That is why the system converts structured outputs into a user-friendly format.
What providers support GLM-5-Turbo?
GLM-5-Turbo is available through Z.AI (direct API) and OpenRouter. Both provide similar pricing and can be used with the same client interface.
Need Help with AI Implementation?
Our experts can help you build browser agents and AI solutions for your business. Get a free consultation to discuss your project requirements.
