'use client'; import { motion } from 'framer-motion'; export function AgentCodeSlide(): React.ReactElement { return (
Step 2

The Agent Loop

Pass meta-tools to generateText with maxSteps

agent.ts
            
              const
               result = 
              await
               generateText
              {'({'}
              {'\n'}
              {'  '}
              model
              : 
              openai
              (
              {"'gpt-4o'"}
              ),
              {'\n'}
              {'  '}
              tools
              {': {'}
              {'\n'}
              {'    '}
              search
              : 
              searchTpmjsToolsTool
              ,
              {'\n'}
              {'    '}
              execute
              : 
              registryExecuteTool
              ,
              {'\n'}
              {'  },'}
              {'\n'}
              {'  '}
              maxSteps
              : 
              10
              ,
              {' // Allow multiple tool calls'}
              {'\n'}
              {'  '}
              system
              : 
              `You are an assistant that can find and use
              {'\n'}
              
                {' '}
                tools from the TPMJS registry. First search for
              
              {'\n'}
               relevant tools, then execute them.`
              ,
              {'\n'}
              {'  '}
              prompt
              : userRequest,
              {'\n'}
              {'});'}
            
          

Key: maxSteps allows the agent to search, then execute, then reason about results

); }