Agent data stored when a tool uses 'Return directly'

Created on 11 June 2025, 13 days ago

Problem/Motivation

I have an AI agent that functions as an assistant. The assistant has history turned off. The agent uses two sub-agent tools, which are prompted to provide a JSON response. Both tools have "Return directly" enabled, as their output doesn’t need to be sent back to the main agent.

In the earlier release of AI Agents version 1.1, this setup worked fine. But now, when a tool returns something directly, the agent job is marked as "Not solved", and the chat history is saved in tempstore.

// Drupal\ai_assistant_api\Service\AgentRunner::runAsAgent

    $agent->determineSolvability();
    // If the agent is still running, we store it for the next run.
    if (!$agent->isFinished()) {
// This gets executed
      $this->tempStore->get('ai_assistant_threads')->set($job_id, $agent->toArray());
    }
    else {
      // Cleanup when finished.
      $this->tempStore->get('ai_assistant_threads')->delete($job_id);
    }

So when the main agent is called for the second time, this stored data gets added to the current request which breaks the agent flow.

I am not sure if this is a bug or this is how it is supposed to work. As a workaround, I am manually deleting the thread after every response

      $response = $this->aiAssistantClient->process();
      // Delete the thread from the temp store after processing.
      $this->tempStore->get('ai_assistant_threads')->delete($this->aiAssistantClient->getThreadsKey());

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.1

Component

Code

Created by

🇮🇳India Akhil Babu Chengannur

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024