Add agent (and small dummy)

This commit is contained in:
2024-10-30 00:32:57 +01:00
parent e1c2e8fb2b
commit 807e7cefb6
7 changed files with 159 additions and 11 deletions

15
agent-solve/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
ARG IMAGE_FROM
FROM $IMAGE_FROM
# become root
USER root
# do somthing as root, e.g. install packages, set up things ...
# RUN ...
# copy the source of the agent in this repo
COPY --chown=user:user ./src/ /ums-agenten/project/src/
# fix permissions
RUN chown -R user:user /ums-agenten
# switch back to user
USER user

View File

59
agent-solve/src/agent.py Normal file
View File

@ -0,0 +1,59 @@
# Agenten Plattform
#
# (c) 2024 Magnus Bender
# Institute of Humanities-Centered Artificial Intelligence (CHAI)
# Universitaet Hamburg
# https://www.chai.uni-hamburg.de/~bender
#
# source code released under the terms of GNU Public License Version 3
# https://www.gnu.org/licenses/gpl-3.0.txt
from typing import Callable
from ums.agent import ExtractTextAgent, SolveAgent, GatekeeperAgent
from ums.utils.types import AgentMessage, Riddle, RiddleData, RiddleSolution, RiddleStatus
"""
Examples for simple agents.
Each agent is represented by its own class. The handling of tasks is done by `handle()` in each agent.
Finally `AGENT_CLASSES` contains the classes of the agents in a list. Via environmental variables this list is specified to the ums.agent system.
"""
class MyExtractTextAgent(ExtractTextAgent):
def before_response(self, response: AgentMessage, send_it: Callable[[], None]) -> bool:
print("The response will be:", response)
return True
def handle(self, data: RiddleData) -> RiddleData:
print("Text Process:", data.file_plain)
return data
class MySolveAgent(SolveAgent):
def handle(self, riddle: Riddle, data: RiddleData) -> RiddleSolution:
if self.message().id == "test":
status = RiddleStatus()
status.extract.required = False
self.sub_riddle(riddle=Riddle(context="Haha", question="Blubber"), status=status)
return RiddleSolution(solution="Huii", explanation="Blubb")
class MyGatekeeperAgent(GatekeeperAgent):
def handle(self, solution: RiddleSolution, riddle: Riddle) -> RiddleSolution:
solution.accepted = True
solution.review = "Ok"
return solution
AGENT_CLASSES = [
MyExtractTextAgent,
MySolveAgent,
MyGatekeeperAgent
]