• About Us
  • Disclaimer
  • Contact Us
  • Privacy Policy
Saturday, July 4, 2026
mGrowTech
No Result
View All Result
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions
No Result
View All Result
mGrowTech
No Result
View All Result
Home Al, Analytics and Automation

How to Build Production-Ready Agentic Systems with Z.AI GLM-5 Using Thinking Mode, Tool Calling, Streaming, and Multi-Turn Workflows

Josh by Josh
April 4, 2026
in Al, Analytics and Automation
0
How to Build Production-Ready Agentic Systems with Z.AI GLM-5 Using Thinking Mode, Tool Calling, Streaming, and Multi-Turn Workflows


print("\n" + "=" * 70)
print("🤖 SECTION 8: Multi-Tool Agentic Loop")
print("=" * 70)
print("Build a complete agent that can use multiple tools across turns.\n")




class GLM5Agent:


   def __init__(self, system_prompt: str, tools: list, tool_registry: dict):
       self.client = ZaiClient(api_key=API_KEY)
       self.messages = [{"role": "system", "content": system_prompt}]
       self.tools = tools
       self.registry = tool_registry
       self.max_iterations = 5


   def chat(self, user_input: str) -> str:
       self.messages.append({"role": "user", "content": user_input})


       for iteration in range(self.max_iterations):
           response = self.client.chat.completions.create(
               model="glm-5",
               messages=self.messages,
               tools=self.tools,
               tool_choice="auto",
               max_tokens=2048,
               temperature=0.6,
           )


           msg = response.choices[0].message
           self.messages.append(msg.model_dump())


           if not msg.tool_calls:
               return msg.content


           for tc in msg.tool_calls:
               fn_name = tc.function.name
               fn_args = json.loads(tc.function.arguments)
               print(f"   🔧 [{iteration+1}] {fn_name}({fn_args})")


               if fn_name in self.registry:
                   result = self.registry[fn_name](**fn_args)
               else:
                   result = {"error": f"Unknown function: {fn_name}"}


               self.messages.append({
                   "role": "tool",
                   "content": json.dumps(result, ensure_ascii=False),
                   "tool_call_id": tc.id,
               })


       return "⚠️ Agent reached maximum iterations without a final answer."




extended_tools = tools + [
   {
       "type": "function",
       "function": {
           "name": "get_current_time",
           "description": "Get the current date and time in ISO format",
           "parameters": {
               "type": "object",
               "properties": {},
               "required": [],
           },
       },
   },
   {
       "type": "function",
       "function": {
           "name": "unit_converter",
           "description": "Convert between units (length, weight, temperature)",
           "parameters": {
               "type": "object",
               "properties": {
                   "value": {"type": "number", "description": "Numeric value to convert"},
                   "from_unit": {"type": "string", "description": "Source unit (e.g., 'km', 'miles', 'kg', 'lbs', 'celsius', 'fahrenheit')"},
                   "to_unit": {"type": "string", "description": "Target unit"},
               },
               "required": ["value", "from_unit", "to_unit"],
           },
       },
   },
]




def get_current_time() -> dict:
   return {"datetime": datetime.now().isoformat(), "timezone": "UTC"}




def unit_converter(value: float, from_unit: str, to_unit: str) -> dict:
   conversions = {
       ("km", "miles"): lambda v: v * 0.621371,
       ("miles", "km"): lambda v: v * 1.60934,
       ("kg", "lbs"): lambda v: v * 2.20462,
       ("lbs", "kg"): lambda v: v * 0.453592,
       ("celsius", "fahrenheit"): lambda v: v * 9 / 5 + 32,
       ("fahrenheit", "celsius"): lambda v: (v - 32) * 5 / 9,
       ("meters", "feet"): lambda v: v * 3.28084,
       ("feet", "meters"): lambda v: v * 0.3048,
   }
   key = (from_unit.lower(), to_unit.lower())
   if key in conversions:
       result = round(conversions[key](value), 4)
       return {"value": value, "from": from_unit, "to": to_unit, "result": result}
   return {"error": f"Conversion {from_unit} → {to_unit} not supported"}




extended_registry = {
   **TOOL_REGISTRY,
   "get_current_time": get_current_time,
   "unit_converter": unit_converter,
}


agent = GLM5Agent(
   system_prompt=(
       "You are a helpful assistant with access to weather, math, time, and "
       "unit conversion tools. Use them whenever they can help answer the user's "
       "question accurately. Always show your work."
   ),
   tools=extended_tools,
   tool_registry=extended_registry,
)


print("🧑 User: What time is it? Also, if it's 28°C in Tokyo, what's that in Fahrenheit?")
print("   And what's 2^16?")
result = agent.chat(
   "What time is it? Also, if it's 28°C in Tokyo, what's that in Fahrenheit? "
   "And what's 2^16?"
)
print(f"\n🤖 Agent: {result}")




print("\n" + "=" * 70)
print("⚖️  SECTION 9: Thinking Mode ON vs OFF Comparison")
print("=" * 70)
print("See how thinking mode improves accuracy on a tricky logic problem.\n")


tricky_question = (
   "I have 12 coins. One of them is counterfeit and weighs differently than the rest. "
)


print("─── WITHOUT Thinking Mode ───")
t0 = time.time()
r_no_think = client.chat.completions.create(
   model="glm-5",
   messages=[{"role": "user", "content": tricky_question}],
   thinking={"type": "disabled"},
   max_tokens=2048,
   temperature=0.6,
)
t1 = time.time()
print(f"⏱️  Time: {t1-t0:.1f}s | Tokens: {r_no_think.usage.completion_tokens}")
print(f"📝 Answer (first 300 chars): {r_no_think.choices[0].message.content[:300]}...")


print("\n─── WITH Thinking Mode ───")
t0 = time.time()
r_think = client.chat.completions.create(
   model="glm-5",
   messages=[{"role": "user", "content": tricky_question}],
   thinking={"type": "enabled"},
   max_tokens=4096,
   temperature=0.6,
)
t1 = time.time()
print(f"⏱️  Time: {t1-t0:.1f}s | Tokens: {r_think.usage.completion_tokens}")
print(f"📝 Answer (first 300 chars): {r_think.choices[0].message.content[:300]}...")



Source_link

READ ALSO

Mistral AI Releases Leanstral 1.5: An Apache-2.0 Lean 4 Code Agent Model Solving 587 of 672 PutnamBench Problems

Meet WebBrain: An Open-Source, Local-First AI Browser Agent That Reads Pages and Automates Tasks in Chrome and Firefox

Related Posts

Mistral AI Releases Leanstral 1.5: An Apache-2.0 Lean 4 Code Agent Model Solving 587 of 672 PutnamBench Problems
Al, Analytics and Automation

Mistral AI Releases Leanstral 1.5: An Apache-2.0 Lean 4 Code Agent Model Solving 587 of 672 PutnamBench Problems

July 4, 2026
Meet WebBrain: An Open-Source, Local-First AI Browser Agent That Reads Pages and Automates Tasks in Chrome and Firefox
Al, Analytics and Automation

Meet WebBrain: An Open-Source, Local-First AI Browser Agent That Reads Pages and Automates Tasks in Chrome and Firefox

July 3, 2026
RAG-Anything Tutorial: Build a Multimodal Retrieval Pipeline for Text, Tables, Equations, and Images in Colab
Al, Analytics and Automation

RAG-Anything Tutorial: Build a Multimodal Retrieval Pipeline for Text, Tables, Equations, and Images in Colab

July 3, 2026
MIT in the media: Innovating and educating for the next 250 years of America | MIT News
Al, Analytics and Automation

MIT in the media: Innovating and educating for the next 250 years of America | MIT News

July 2, 2026
Using Lift to Turn Research PDFs into Structured JSON with Controlled, Schema-Guided Field-Level Evaluation
Al, Analytics and Automation

Using Lift to Turn Research PDFs into Structured JSON with Controlled, Schema-Guided Field-Level Evaluation

July 2, 2026
3 Questions: Beyond data-driven aesthetics | MIT News
Al, Analytics and Automation

3 Questions: Beyond data-driven aesthetics | MIT News

July 1, 2026
Next Post
Maytag Promo Codes and Deals: Appliances Under $300

Maytag Promo Codes and Deals: Appliances Under $300

POPULAR NEWS

Trump ends trade talks with Canada over a digital services tax

Trump ends trade talks with Canada over a digital services tax

June 28, 2025
15 Trending Songs on TikTok in 2025 (+ How to Use Them)

15 Trending Songs on TikTok in 2025 (+ How to Use Them)

June 18, 2025
Communication Effectiveness Skills For Business Leaders

Communication Effectiveness Skills For Business Leaders

June 10, 2025
App Development Cost in Singapore: Pricing Breakdown & Insights

App Development Cost in Singapore: Pricing Breakdown & Insights

June 22, 2025
Comparing the Top 7 Large Language Models LLMs/Systems for Coding in 2025

Comparing the Top 7 Large Language Models LLMs/Systems for Coding in 2025

November 4, 2025

EDITOR'S PICK

How to Get Free Seeds in Grow a Garden

How to Get Free Seeds in Grow a Garden

September 2, 2025
Towards a Multimodal Transportation Data Framework

Towards a Multimodal Transportation Data Framework

June 5, 2025
Watch The Brief, Live! July 2025 Edition: San Diego Comic-Con

Watch The Brief, Live! July 2025 Edition: San Diego Comic-Con

August 1, 2025
Logo & Branding for Double Diamond by Alec Tear — BP&O

Logo & Branding for Double Diamond by Alec Tear — BP&O

October 28, 2025

About

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow us

Categories

  • Account Based Marketing
  • Ad Management
  • Al, Analytics and Automation
  • Brand Management
  • Channel Marketing
  • Digital Marketing
  • Direct Marketing
  • Event Management
  • Google Marketing
  • Marketing Attribution and Consulting
  • Marketing Automation
  • Mobile Marketing
  • PR Solutions
  • Social Media Management
  • Technology And Software
  • Uncategorized

Recent Posts

  • The Space Shuttle Endeavour Goes On Public Display Later This Year
  • Mistral AI Releases Leanstral 1.5: An Apache-2.0 Lean 4 Code Agent Model Solving 587 of 672 PutnamBench Problems
  • 10 Tips for a Successful and Engaging Virtual Camp
  • Google Play Indie Games Fund in Africa
  • About Us
  • Disclaimer
  • Contact Us
  • Privacy Policy
No Result
View All Result
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions