OpenAgentsInc / openagents

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

Enhancement: Read AI prompt from file #418

Open dekdynamics opened 1 month ago

dekdynamics commented 1 month ago

Hi,

This is a request for an enhancement to the AI agent behaviour.

My ideal scenario is that I would have a file called KB.md or (.txt), which serves as the extended agent prompt.

In this file, I would explain details of what the agent should do, how it should respond, explanations of the files in its repository, and minutiae regarding the topics it should know.

Here is an example of the syntax I started with, but I am open to anything:

cat knowledge-files/KB.txt
KNOWLEDGEBASE

This document contains information about the other files in your knowledge repository.

Filename BOLT*
- These files, beginning with BOLT, define the bitcoin lightning specifications.
- The number in the filename indicates the BOLT ID number
- If there is no number in the filename, the BOLT is a proposal and not part of the current spec

Filename BOLT-PROPOSAL*
- A proposal to the BOLT specification
- The route-blinding specification is sometimes referred to as BOLT 12, even though its not ratified in the spec
- BOLT 12 contains details about offers, which is a method by which a payer can obtain an invoice from a payee without interaction from the payee
- When you describe BOLT 12, be sure to mention that it is a BOLT proposal, and not ratified in the spec

Filename lightning-node*
- These files introduce lightning node software
- These files are the github README.md files from their respective repositories

Filename whitepaper*
- These files are academic-style publications that explain or introduce Bitcoin and related technologies
greptile-apps[bot] commented 1 month ago

To implement reading AI prompts from a file, follow these steps:

  1. Modify SimpleInferencer.php:

    • Update the inference method to read the contents of KB.md or KB.txt and include it in the systemPrompt.
      public function inference(string $prompt, string $model, Thread $thread, callable $streamFunction, string $systemPrompt = ''): array
      {
      $kbFilePath = 'path/to/knowledge-files/KB.txt';
      if (file_exists($kbFilePath)) {
         $systemPrompt = file_get_contents($kbFilePath);
      }
      // existing code...
      }
  2. Update AI Gateway Classes:

    • Ensure each gateway class (e.g., OpenAIGateway.php, AnthropicAIGateway.php) correctly handles the updated systemPrompt.
    • Example for OpenAIGateway.php:
      public function inference(array $params): array
      {
      $model = $params['model'];
      $messages = $params['messages'];
      $streamFunction = $params['stream_function'];
      $systemPrompt = $params['system_prompt'] ?? 'You are a helpful assistant.';
      // existing code...
      }
  3. Update Livewire Components:

    • Modify create.blade.php and edit.blade.php to include a file upload field for the knowledge base file.
      <x-filepond wire:model="kbFile" />
    • Handle the file upload in the corresponding Livewire component.
      
      public $kbFile;

    public function submit() { if ($this->kbFile) { $this->kbFile->storeAs('knowledge-files', 'KB.txt'); } // existing code... }

  4. Update SimpleInferencer.php to Pass systemPrompt:

    • Ensure the systemPrompt is passed to the gateway classes.
      $params = [
      'model' => $model,
      'messages' => $messages,
      'max_tokens' => $this->remainingTokens,
      'stream_function' => $streamFunction,
      'system_prompt' => $systemPrompt,
      ];

References

/app/AI/SimpleInferencer.php /app/AI/GatewayInterface.php /app/AI/OpenAIGateway.php /app/AI/AnthropicAIGateway.php /app/AI/CohereAIGateway.php /app/AI/GeminiAIGateway.php /app/AI/GreptileGateway.php /app/AI/GroqAIGateway.php /app/AI/HuggingfaceAIGateway.php /app/AI/MistralAIGateway.php /app/AI /resources/views/livewire/agents /resources/views/livewire/agents/create.blade.php /resources/views/livewire/agents/edit.blade.php

Ask Greptile