Close Menu
    Facebook X (Twitter) Instagram
    Articles Stock
    • Home
    • Technology
    • AI
    • Pages
      • About us
      • Contact us
      • Disclaimer For Articles Stock
      • Privacy Policy
      • Terms and Conditions
    Facebook X (Twitter) Instagram
    Articles Stock
    AI

    Tips on how to Construct Manufacturing-Prepared Agentic Techniques with Z.AI GLM-5 Utilizing Pondering Mode, Device Calling, Streaming, and Multi-Flip Workflows

    Naveed AhmadBy Naveed Ahmad04/04/2026Updated:04/04/2026No Comments3 Mins Read
    blog 7


    print("n" + "=" * 70)
    print("šŸ¤– SECTION 8: Multi-Device Agentic Loop")
    print("=" * 70)
    print("Construct a whole agent that may use a number of instruments throughout turns.n")
    
    
    
    
    class GLM5Agent:
    
    
       def __init__(self, system_prompt: str, instruments: checklist, tool_registry: dict):
           self.consumer = ZaiClient(api_key=API_KEY)
           self.messages = [{"role": "system", "content": system_prompt}]
           self.instruments = instruments
           self.registry = tool_registry
           self.max_iterations = 5
    
    
       def chat(self, user_input: str) -> str:
           self.messages.append({"position": "person", "content material": user_input})
    
    
           for iteration in vary(self.max_iterations):
               response = self.consumer.chat.completions.create(
                   mannequin="glm-5",
                   messages=self.messages,
                   instruments=self.instruments,
                   tool_choice="auto",
                   max_tokens=2048,
                   temperature=0.6,
               )
    
    
               msg = response.decisions[0].message
               self.messages.append(msg.model_dump())
    
    
               if not msg.tool_calls:
                   return msg.content material
    
    
               for tc in msg.tool_calls:
                   fn_name = tc.perform.identify
                   fn_args = json.masses(tc.perform.arguments)
                   print(f"   šŸ”§ [{iteration+1}] {fn_name}({fn_args})")
    
    
                   if fn_name in self.registry:
                       outcome = self.registry[fn_name](**fn_args)
                   else:
                       outcome = {"error": f"Unknown perform: {fn_name}"}
    
    
                   self.messages.append({
                       "position": "software",
                       "content material": json.dumps(outcome, ensure_ascii=False),
                       "tool_call_id": tc.id,
                   })
    
    
           return "āš ļø Agent reached most iterations with out a remaining reply."
    
    
    
    
    extended_tools = instruments + [
       {
           "type": "function",
           "function": {
               "name": "get_current_time",
               "description": "Get the current date and time in ISO format",
               "parameters": {
                   "type": "object",
                   "properties": {},
                   "required": [],
               },
           },
       },
       {
           "sort": "perform",
           "perform": {
               "identify": "unit_converter",
               "description": "Convert between models (size, weight, temperature)",
               "parameters": {
                   "sort": "object",
                   "properties": {
                       "worth": {"sort": "quantity", "description": "Numeric worth to transform"},
                       "from_unit": {"sort": "string", "description": "Supply unit (e.g., 'km', 'miles', 'kg', 'lbs', 'celsius', 'fahrenheit')"},
                       "to_unit": {"sort": "string", "description": "Goal unit"},
                   },
                   "required": ["value", "from_unit", "to_unit"],
               },
           },
       },
    ]
    
    
    
    
    def get_current_time() -> dict:
       return {"datetime": datetime.now().isoformat(), "timezone": "UTC"}
    
    
    
    
    def unit_converter(worth: 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", "toes"): lambda v: v * 3.28084,
           ("toes", "meters"): lambda v: v * 0.3048,
       }
       key = (from_unit.decrease(), to_unit.decrease())
       if key in conversions:
           outcome = spherical(conversions[key](worth), 4)
           return {"worth": worth, "from": from_unit, "to": to_unit, "outcome": outcome}
       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're a useful assistant with entry to climate, math, time, and "
           "unit conversion instruments. Use them each time they may also help reply the person's "
           "query precisely. At all times present your work."
       ),
       instruments=extended_tools,
       tool_registry=extended_registry,
    )
    
    
    print("šŸ§‘ Consumer: What time is it? Additionally, if it is 28°C in Tokyo, what's that in Fahrenheit?")
    print("   And what's 2^16?")
    outcome = agent.chat(
       "What time is it? Additionally, if it is 28°C in Tokyo, what's that in Fahrenheit? "
       "And what's 2^16?"
    )
    print(f"nšŸ¤– Agent: {outcome}")
    
    
    
    
    print("n" + "=" * 70)
    print("āš–ļø  SECTION 9: Pondering Mode ON vs OFF Comparability")
    print("=" * 70)
    print("See how pondering mode improves accuracy on a tough logic downside.n")
    
    
    tricky_question = (
       "I've 12 cash. Considered one of them is counterfeit and weighs in another way than the remaining. "
    )
    
    
    print("─── WITHOUT Pondering Mode ───")
    t0 = time.time()
    r_no_think = consumer.chat.completions.create(
       mannequin="glm-5",
       messages=[{"role": "user", "content": tricky_question}],
       pondering={"sort": "disabled"},
       max_tokens=2048,
       temperature=0.6,
    )
    t1 = time.time()
    print(f"ā±ļø  Time: {t1-t0:.1f}s | Tokens: {r_no_think.utilization.completion_tokens}")
    print(f"šŸ“ Reply (first 300 chars): {r_no_think.decisions[0].message.content material[:300]}...")
    
    
    print("n─── WITH Pondering Mode ───")
    t0 = time.time()
    r_think = consumer.chat.completions.create(
       mannequin="glm-5",
       messages=[{"role": "user", "content": tricky_question}],
       pondering={"sort": "enabled"},
       max_tokens=4096,
       temperature=0.6,
    )
    t1 = time.time()
    print(f"ā±ļø  Time: {t1-t0:.1f}s | Tokens: {r_think.utilization.completion_tokens}")
    print(f"šŸ“ Reply (first 300 chars): {r_think.decisions[0].message.content material[:300]}...")



    Source link

    Naveed Ahmad

    Related Posts

    OpenAI government shuffle consists of new function for COO Brad Lightcap to guide ‘particular initiatives’

    04/04/2026

    The nameless social app that thinks it might work in Saudi Arabia

    04/04/2026

    Anthropic is having a second within the non-public markets; SpaceX may spoil the social gathering

    04/04/2026
    Leave A Reply Cancel Reply

    Categories
    • AI
    Recent Comments
      Facebook X (Twitter) Instagram Pinterest
      © 2026 ThemeSphere. Designed by ThemeSphere.

      Type above and press Enter to search. Press Esc to cancel.