• bitcoinBitcoin(BTC)$77,138.00-0.19%
  • ethereumEthereum(ETH)$2,499.96-0.95%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$720.86-0.80%
  • rippleXRP(XRP)$1.35-0.97%
  • usd-coinUSDC(USDC)$1.00-0.01%
  • solanaSolana(SOL)$100.94-0.66%
  • tronTRON(TRX)$0.3411450.40%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.000.00%
  • zcashZcash(ZEC)$1,089.94-3.04%
  • HyperliquidHyperliquid(HYPE)$78.34-1.63%
  • dogecoinDogecoin(DOGE)$0.083730-1.25%
  • RainRain(RAIN)$0.015254-3.33%
  • moneroMonero(XMR)$530.23-1.34%
  • USDSUSDS(USDS)$1.00-0.01%
  • whitebitWhiteBIT Coin(WBT)$79.99-0.46%
  • chainlinkChainlink(LINK)$11.37-1.27%
  • leo-tokenLEO Token(LEO)$9.02-1.57%
  • cardanoCardano(ADA)$0.206692-0.29%
  • stellarStellar(XLM)$0.179741-0.17%
  • Ethena USDeEthena USDe(USDE)$1.00-0.02%
  • daiDai(DAI)$1.00-0.01%
  • bitcoin-cashBitcoin Cash(BCH)$223.50-1.09%
  • USD1USD1(USD1)$1.00-0.01%
  • litecoinLitecoin(LTC)$54.481.59%
  • uniswapUniswap(UNI)$6.22-2.28%
  • CantonCanton(CC)$0.095573-1.66%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.36-1.92%
  • hedera-hashgraphHedera(HBAR)$0.0761992.24%
  • Global DollarGlobal Dollar(USDG)$1.00-0.01%
  • avalanche-2Avalanche(AVAX)$7.410.13%
  • shiba-inuShiba Inu(SHIB)$0.000005-1.46%
  • nearNEAR Protocol(NEAR)$2.33-1.01%
  • suiSui(SUI)$0.71-1.23%
  • crypto-com-chainCronos(CRO)$0.058210-2.48%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.01%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • tether-goldTether Gold(XAUT)$4,335.02-0.40%
  • MemeCoreMemeCore(M)$1.15-2.85%
  • Circle USYCCircle USYC(USYC)$1.140.00%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • okbOKB(OKB)$112.88-0.86%
  • BittensorBittensor(TAO)$235.471.19%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.14-0.10%
  • BitwayBitway(BTW)$0.7230.22%
  • aaveAave(AAVE)$125.73-0.04%
  • AsterAster(ASTER)$0.701.19%
  • pax-goldPAX Gold(PAXG)$4,340.96-0.37%
  • mantleMantle(MNT)$0.56-0.78%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.056995-1.85%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

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

April 4, 2026
in AI & Technology
Reading Time: 3 mins read
A A
How to Build Production-Ready Agentic Systems with Z.AI GLM-5 Using Thinking Mode, Tool Calling, Streaming, and Multi-Turn Workflows
ShareShareShareShareShare

YOU MAY ALSO LIKE

How To Adjust The Liquid Glass Effect On Your iPhone With iOS 27

Car Manufacturers Are Ditching CarPlay In 2026: Here’s Why

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]}...")

Credit: Source link

ShareTweetSendSharePin

Related Posts

How To Adjust The Liquid Glass Effect On Your iPhone With iOS 27
AI & Technology

How To Adjust The Liquid Glass Effect On Your iPhone With iOS 27

September 13, 2026
Car Manufacturers Are Ditching CarPlay In 2026: Here’s Why
AI & Technology

Car Manufacturers Are Ditching CarPlay In 2026: Here’s Why

September 13, 2026
A Princeton Researcher Proposes Recurrent Looped Transformer (RLT) that Carries Decoder State across Every Token, Fixing 96 Blocks per Token with Unbounded Temporal Depth
AI & Technology

A Princeton Researcher Proposes Recurrent Looped Transformer (RLT) that Carries Decoder State across Every Token, Fixing 96 Blocks per Token with Unbounded Temporal Depth

September 13, 2026
Johnson Proposes White House Meeting of AI Leaders on Guardrails – Unite.AI
AI & Technology

Johnson Proposes White House Meeting of AI Leaders on Guardrails – Unite.AI

September 13, 2026
Next Post
Anthropic cuts off the ability to use Claude subscriptions with OpenClaw and third-party AI agents

Anthropic cuts off the ability to use Claude subscriptions with OpenClaw and third-party AI agents

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Rabies cases increased 17 percent in July and August, CDC says – The Washington Post

Rabies cases increased 17 percent in July and August, CDC says – The Washington Post

September 11, 2026
Russia struck train near Poland border shortly after Boris Johnson and top European officials passed through – BBC

Russia struck train near Poland border shortly after Boris Johnson and top European officials passed through – BBC

September 13, 2026
What Is The Anker ‘Smart Display Charger’ And What Does That Screen Even Do?

What Is The Anker ‘Smart Display Charger’ And What Does That Screen Even Do?

September 8, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!