#Agent does not continue after tool-result

4 messages · Page 1 of 1 (latest)

formal meteor
#

Hey,
I have an agent set up with a rag-search tool.

I am building a multi tenant system so I create my Agent with its tenant-context-tool on demand for each request.

I have a simple streaming setup pretty much straight out of the docs.

When I send a message to the agent I can see it calls the search tool, I can see the tool responds with some text from the RAG search.

The issue is that the thread stops here - the agent does not pick up on the tool-result - and does not generate the actual response for the user.

Any thoughts?

Thanks

crystal valleyBOT
#

Hi @formal meteor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It sounds like your agent is successfully calling the RAG search tool and receiving a tool-result, but then does not proceed to generate a final response for the user. Based on the Convex documentation, here are some things to check:

  1. maxSteps Configuration
    For the agent to automatically continue after a tool call (i.e., after receiving a tool-result), you need to set maxSteps to a value greater than 1. By default, maxSteps is 1, which means the agent will only take a single step (e.g., call the tool, but not continue to generate a final response). Setting maxSteps higher allows the agent to chain tool calls and generate a final response in one go:

    const agent = new Agent(components.agent, {
      // ...
      maxSteps: 3, // or higher, depending on your workflow
    });
    

    Or, you can set it per call:

    await thread.generateText({ prompt }, { maxSteps: 3 });
    

    See docs for details

  2. Streaming and Consuming the Stream
    If you are using streaming (e.g., streamText), make sure you are consuming the stream fully. The agent may not complete all steps if the stream is not fully consumed:

    const result = await thread.streamText({ prompt }, { saveStreamDeltas: true });
    await result.consumeStream();
    

    See streaming docs

  3. Tool Call Handling
    The agent should automatically handle tool calls and continue, provided maxSteps is set correctly. If you are dynamically creating the agent or tools per request, ensure that the tool definitions and agent options are consistent and that the tool's handler returns the expected result.

#
  1. Debugging
    Use the Playground or add a rawRequestResponseHandler to your agent to log the LLM requests and responses for further insight:

    const agent = new Agent(components.agent, {
      // ...
      rawRequestResponseHandler: async (ctx, { request, response }) => {
        console.log("request", request);
        console.log("response", response);
      },
    });
    

    Debugging reference

Summary:
The most likely cause is that maxSteps is not set high enough, so the agent stops after the tool call. Try increasing maxSteps either on the agent or per call, and ensure you are fully consuming the stream if using streaming. If the issue persists, use debugging tools to inspect the agent's behavior.

Let me know if adjusting maxSteps resolves your issue!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: