Run single tasks

This commit is contained in:
2024-10-30 20:24:12 +01:00
parent f2b9df7611
commit 786a230e78
9 changed files with 500 additions and 248 deletions

View File

@ -28,6 +28,12 @@
<input type="search" placeholder="Search..." role="searchbox" aria-label="search"
pattern=".+" required>
<h2>Contents</h2>
<ul>
<li><a href="#run-as-agent">Run as Agent</a></li>
<li><a href="#run-single-task">Run Single Task</a></li>
</ul>
<h2>Submodules</h2>
<ul>
@ -50,7 +56,47 @@
<h1 class="modulename">
<a href="./../ums.html">ums</a><wbr>.agent </h1>
<div class="docstring"><h2 id="run-as-agent">Run as Agent</h2>
<p>The env. variable <code>AGENTS_LIST</code> is used to identify the agents classes/ task handlers.
It must contain he the package name and a variable name in this package divided by <code>:</code>.
Then, the variable contains a list of agent classes (subclasses of <code><a href="agent/agent.html#BasicAgent">ums.agent.agent.BasicAgent</a></code>)</p>
<p>For example <code>AGENTS_LIST=ums.example.example:AGENT_CLASSES</code>, then in file <code>./ums/example/example.py</code> a variable <code>AGENT_CLASSES</code> exists.
One line in this file, e.g., is <code>AGENT_CLASSES = [MyExtractAudioAgent, MyExtractImageAgent]</code>.</p>
<p>When starting the Docker container of the agent, the classes specified in <code>AGENTS_LIST</code> are loaded and if the agent receives a task, the task is sent to the agent classes' <code>handle</code> methods.</p>
<h2 id="run-single-task">Run Single Task</h2>
<p>For development it might be cumbersome to always require a running management container and sending messages.
Hence, tasks can be run manually from the terminal (still in the container and using the agent classes), but without having a management.</p>
<p>This also uses the <code>AGENTS_LIST</code> env. variable, but the tasks are sent via command line:</p>
<p>There are three ways to send a task (if the agent's Docker container is running):</p>
<ul>
<li><code>docker compose exec agent_all python -m <a href="">ums.agent</a> -d</code>
<ul>
<li>Run a dummy task</li>
<li>Possibly <code>agent_all</code> needs to be changed to the service name (see <code>docker-compose.yml</code>) of the agent's Docker container</li>
</ul></li>
<li><code>cat ./msg.json | docker compose exec -T agent_all python -m <a href="">ums.agent</a> -i</code>
<ul>
<li>Send the task (json of <code>AgentMessage</code>) via STDIN from file <code>./msg.json</code> to the agent</li>
</ul></li>
<li><code>docker compose exec agent_all python -m <a href="">ums.agent</a> -f msg.json</code>
<ul>
<li>Get the task from the json file, the files are searched for by full name, in the shared, and the persistent directory.</li>
</ul></li>
</ul>
<p>If the Agent's Docker container is not running, a temporary container can be started.
For the dummy message, the command would be <code>docker compose run --rm --entrypoint "" agent_all python -m <a href="">ums.agent</a> -d</code>.
(Again, change <code>agent_all</code> for the service name in <code>docker-compose.yml</code>.)</p>
</div>
<input id="mod-agent-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
<label class="view-source-button" for="mod-agent-view-source"><span>View Source</span></label>
@ -65,14 +111,49 @@
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="c1"># source code released under the terms of GNU Public License Version 3</span>
</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a><span class="c1"># https://www.gnu.org/licenses/gpl-3.0.txt</span>
</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="kn">from</span> <span class="nn">ums.agent.agent</span> <span class="kn">import</span> <span class="p">(</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a> <span class="n">AgentCapability</span><span class="p">,</span>
</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a> <span class="n">BasicAgent</span><span class="p">,</span>
</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a> <span class="n">ExtractAgent</span><span class="p">,</span>
</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a> <span class="n">ExtractAudioAgent</span><span class="p">,</span> <span class="n">ExtractImageAgent</span><span class="p">,</span> <span class="n">ExtractTextAgent</span><span class="p">,</span>
</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a> <span class="n">SolveAgent</span><span class="p">,</span>
</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a> <span class="n">GatekeeperAgent</span>
</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a><span class="p">)</span>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="sd">&quot;&quot;&quot;</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a>
</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a><span class="sd">## Run as Agent</span>
</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a>
</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a><span class="sd">The env. variable `AGENTS_LIST` is used to identify the agents classes/ task handlers.</span>
</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a><span class="sd">It must contain he the package name and a variable name in this package divided by `:`. </span>
</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a><span class="sd">Then, the variable contains a list of agent classes (subclasses of `ums.agent.agent.BasicAgent`)</span>
</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a>
</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a><span class="sd">For example `AGENTS_LIST=ums.example.example:AGENT_CLASSES`, then in file `./ums/example/example.py` a variable `AGENT_CLASSES` exists. </span>
</span><span id="L-20"><a href="#L-20"><span class="linenos">20</span></a><span class="sd">One line in this file, e.g., is `AGENT_CLASSES = [MyExtractAudioAgent, MyExtractImageAgent]`.</span>
</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a>
</span><span id="L-22"><a href="#L-22"><span class="linenos">22</span></a><span class="sd">When starting the Docker container of the agent, the classes specified in `AGENTS_LIST` are loaded and if the agent receives a task, the task is sent to the agent classes&#39; `handle` methods.</span>
</span><span id="L-23"><a href="#L-23"><span class="linenos">23</span></a>
</span><span id="L-24"><a href="#L-24"><span class="linenos">24</span></a><span class="sd">## Run Single Task</span>
</span><span id="L-25"><a href="#L-25"><span class="linenos">25</span></a>
</span><span id="L-26"><a href="#L-26"><span class="linenos">26</span></a><span class="sd">For development it might be cumbersome to always require a running management container and sending messages. </span>
</span><span id="L-27"><a href="#L-27"><span class="linenos">27</span></a><span class="sd">Hence, tasks can be run manually from the terminal (still in the container and using the agent classes), but without having a management.</span>
</span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a>
</span><span id="L-29"><a href="#L-29"><span class="linenos">29</span></a><span class="sd">This also uses the `AGENTS_LIST` env. variable, but the tasks are sent via command line:</span>
</span><span id="L-30"><a href="#L-30"><span class="linenos">30</span></a>
</span><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a><span class="sd">There are three ways to send a task (if the agent&#39;s Docker container is running):</span>
</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a><span class="sd">- `docker compose exec agent_all python -m ums.agent -d`</span>
</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a><span class="sd"> - Run a dummy task</span>
</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a><span class="sd"> - Possibly `agent_all` needs to be changed to the service name (see `docker-compose.yml`) of the agent&#39;s Docker container</span>
</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a><span class="sd">- `cat ./msg.json | docker compose exec -T agent_all python -m ums.agent -i`</span>
</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a><span class="sd"> - Send the task (json of `AgentMessage`) via STDIN from file `./msg.json` to the agent</span>
</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a><span class="sd">- `docker compose exec agent_all python -m ums.agent -f msg.json`</span>
</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a><span class="sd"> - Get the task from the json file, the files are searched for by full name, in the shared, and the persistent directory.</span>
</span><span id="L-39"><a href="#L-39"><span class="linenos">39</span></a>
</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a><span class="sd">If the Agent&#39;s Docker container is not running, a temporary container can be started.</span>
</span><span id="L-41"><a href="#L-41"><span class="linenos">41</span></a><span class="sd">For the dummy message, the command would be `docker compose run --rm --entrypoint &quot;&quot; agent_all python -m ums.agent -d`.</span>
</span><span id="L-42"><a href="#L-42"><span class="linenos">42</span></a><span class="sd">(Again, change `agent_all` for the service name in `docker-compose.yml`.)</span>
</span><span id="L-43"><a href="#L-43"><span class="linenos">43</span></a>
</span><span id="L-44"><a href="#L-44"><span class="linenos">44</span></a><span class="sd">&quot;&quot;&quot;</span>
</span><span id="L-45"><a href="#L-45"><span class="linenos">45</span></a>
</span><span id="L-46"><a href="#L-46"><span class="linenos">46</span></a><span class="kn">from</span> <span class="nn">ums.agent.agent</span> <span class="kn">import</span> <span class="p">(</span>
</span><span id="L-47"><a href="#L-47"><span class="linenos">47</span></a> <span class="n">AgentCapability</span><span class="p">,</span>
</span><span id="L-48"><a href="#L-48"><span class="linenos">48</span></a> <span class="n">BasicAgent</span><span class="p">,</span>
</span><span id="L-49"><a href="#L-49"><span class="linenos">49</span></a> <span class="n">ExtractAgent</span><span class="p">,</span>
</span><span id="L-50"><a href="#L-50"><span class="linenos">50</span></a> <span class="n">ExtractAudioAgent</span><span class="p">,</span> <span class="n">ExtractImageAgent</span><span class="p">,</span> <span class="n">ExtractTextAgent</span><span class="p">,</span>
</span><span id="L-51"><a href="#L-51"><span class="linenos">51</span></a> <span class="n">SolveAgent</span><span class="p">,</span>
</span><span id="L-52"><a href="#L-52"><span class="linenos">52</span></a> <span class="n">GatekeeperAgent</span>
</span><span id="L-53"><a href="#L-53"><span class="linenos">53</span></a><span class="p">)</span>
</span></pre></div>