OpenAgentsInc / openagents

An open agents platform (wip)
https://openagents.com
GNU Affero General Public License v3.0
158 stars 19 forks source link

Agent stalled mid-reply #419

Closed dekdynamics closed 1 month ago

dekdynamics commented 1 month ago

Hi Team,

I get this behaviour very often:

image

While this is happening, I can't stop the reply or say anything new in the chat.

This one has been stuck for ~10 minutes, but typically it never returns and I start a new chat.

greptile-apps[bot] commented 1 month ago

To address the issue of the agent stalling mid-reply, follow these steps:

  1. Check sendMessage Method in Chat.php:

    • Ensure there are no infinite loops or unhandled exceptions in the sendMessage method.
    • File: /app/Livewire/Chat.php
      public function sendMessage(): void
      {
      // Existing code...
      try {
         // Your logic here
      } catch (Exception $e) {
         $this->alert('error', 'An error occurred, please try again later');
         Log::error($e);
         $this->pending = false;
      }
      }
  2. Review AI Gateway Inference Methods:

    • Check for potential infinite loops or unhandled exceptions in the inference methods of the various AI gateways.
    • Files to check:
      • /app/AI/OpenAIGateway.php
      • /app/AI/ReplicateAIGateway.php
      • /app/AI/PerplexityAIGateway.php
      • /app/AI/TogetherAIGateway.php
      • /app/AI/AnthropicAIGateway.php
      • /app/AI/HuggingfaceAIGateway.php
      • /app/AI/CohereAIGateway.php
      • /app/AI/GroqAIGateway.php
      • /app/AI/MistralAIGateway.php
        public function inference(array $params): array
        {
        // Existing code...
        try {
        // Your logic here
        } catch (Exception $e) {
        Log::error($e);
        return ['content' => 'An error occurred, please try again later', 'input_tokens' => 0, 'output_tokens' => 0];
        }
        }
  3. Add Logging for Debugging:

    • Add logging statements to trace the flow and identify where it might be stalling.
      Log::debug('Debug message');
  4. Handle Streaming Callback:

    • Ensure the streaming callback in Chat.php is properly handling exceptions.
      private function getStreamingCallback(): callable
      {
      return function ($content, bool $replace = false) {
         try {
             $this->stream(
                 to: 'streamtext'.$this->thread->id,
                 content: $content,
                 replace: $replace,
             );
         } catch (Exception $e) {
             Log::error($e);
             $this->pending = false;
         }
      };
      }

References

/app/Livewire/Chat.php /app/AI/NostrRag.php /app/AI/OpenAIGateway.php /app/AI/ReplicateAIGateway.php /app/AI/PerplexityAIGateway.php /app/AI/TogetherAIGateway.php /app/AI/AnthropicAIGateway.php /app/AI/HuggingfaceAIGateway.php /app/AI/CohereAIGateway.php /app/AI/GroqAIGateway.php /app/AI/MistralAIGateway.php

Ask Greptile

svemir commented 1 month ago

We are limited by how livewire streaming works here. See https://github.com/livewire/livewire/discussions/7882

Perhaps in this specific case there is a simpler answer, but we would have to replicate the issue locally first.

dekdynamics commented 1 month ago

Try the same question for the Fast Talking Man agent. It happens to me every time I ask this question.

I just tried again right now and its been stuck here for over 2 minutes:

image