Notes 18.09.
This commit is contained in:
parent
28d579ce59
commit
622f8bc009
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM git.chai.uni-hamburg.de/ums-agenten/base-process:cpu
|
||||||
|
|
||||||
|
RUN apt install my-pkg
|
71
Readme.md
71
Readme.md
@ -1,73 +1,2 @@
|
|||||||
# Agenten-Plattform
|
# Agenten-Plattform
|
||||||
|
|
||||||
## Allgemein
|
|
||||||
- Docker Container
|
|
||||||
- Ein Manager-Agent
|
|
||||||
- Viele Worker-Agenten
|
|
||||||
- JSON Post Requests
|
|
||||||
- Studis erstellen Worker-Agenten
|
|
||||||
- Library vorgegeben
|
|
||||||
- HTTP-Server für Tasks, Ergebnisse per HTTP an Manager
|
|
||||||
- Worker registriert sich beim Manager mit
|
|
||||||
- Seiner IP/ HTTP Schnittstelle
|
|
||||||
- Seinen Fähigkeiten (Capabilities)
|
|
||||||
|
|
||||||
## Agent Capabilities
|
|
||||||
-
|
|
||||||
- Vorverarbeitung
|
|
||||||
- Evaluation
|
|
||||||
|
|
||||||
## Example
|
|
||||||
- Manager und einfache Worker
|
|
||||||
|
|
||||||
|
|
||||||
## Requests
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"type" : "register" // "unregister",
|
|
||||||
"body" : {
|
|
||||||
"capabilities" : [""],
|
|
||||||
"endpoint" : "10.0.0.12:8080"
|
|
||||||
},
|
|
||||||
"sender-id" : "worker1",
|
|
||||||
"comment" : "",
|
|
||||||
"error" : false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"type" : "task",
|
|
||||||
"task-id" : "t12",
|
|
||||||
"capability" : "",
|
|
||||||
"body" : {
|
|
||||||
|
|
||||||
},
|
|
||||||
"sender-id" : "manager",
|
|
||||||
"comment" : "",
|
|
||||||
"error" : false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"type" : "response",
|
|
||||||
"task-id" : "t12"
|
|
||||||
"body" : {
|
|
||||||
|
|
||||||
},
|
|
||||||
"sender-id" : "worker1",
|
|
||||||
"comment" : "",
|
|
||||||
"error" : false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Aufgabe
|
|
||||||
- Online-Escape-Room
|
|
||||||
- Unterlagen, die zum "Ausgang" führen
|
|
||||||
- Eingabe: Unterlagen für Rätsel (Audio, Text, Bilder, ...) [ZIP, JSON]
|
|
||||||
- Vorverarbeitung: Agent je für Audio, Text, Bild (→ alles textlich)
|
|
||||||
- Analyse:
|
|
||||||
- Ausgabe: Lösung & Erklärung
|
|
||||||
- Ziel: Finde Lösung mit Erklärung
|
|
132
Requests.md
Normal file
132
Requests.md
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
### Ablauf
|
||||||
|
1. Daten und Rästel eingeben
|
||||||
|
- an Management von Benutzer (oder als Subrätsel)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"riddle" : {
|
||||||
|
"context" : "The values of the variables of the following math problem are given in the text document as written numbers.",
|
||||||
|
"question" : "What is x+y?",
|
||||||
|
"solution_before" : "", # if trial > 0
|
||||||
|
"review_before": "" # if trial > 0
|
||||||
|
},
|
||||||
|
"trial" : 0, # did we try this before
|
||||||
|
"steps" : {
|
||||||
|
"extract" : true,
|
||||||
|
"solve" : true,
|
||||||
|
"validate": true,
|
||||||
|
},
|
||||||
|
"data" : [
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. Daten verteilen (`if "extract" : true`)
|
||||||
|
- an alle "🤖 Daten einlesen" vom Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"data" : [
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
3. Verarbeitete Daten annehmen (`if "extract" : true|false`)
|
||||||
|
- von allen "🤖 Daten einlesen" an Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"data" : [
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt",
|
||||||
|
"extraction" : "./my-test.json" # schema für alle gleich
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
4. Rätsel lösen (`if "solve" : true|false`)
|
||||||
|
- an (alle) "🤖 Lösung bestimmen" von Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"riddle" : { ... },
|
||||||
|
"data" : [
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt",
|
||||||
|
"extraction" : "./my-test.json"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Muss ein "Subrätsel" erzeugen (können), wenn weitere Datenanalyse notwenig ist
|
||||||
|
- Mit einer Submenge der Daten bzw. konkreten Fragen etc.
|
||||||
|
5. Lösung eines Rätsel annehmen (`if "solve" : true`)
|
||||||
|
- von (alle) "🤖 Lösung bestimmen" an Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"solution" : "26",
|
||||||
|
"explanation" : "x = 12, y = 14, ...",
|
||||||
|
"sub_riddles" : [ # optional
|
||||||
|
"xyz-1",
|
||||||
|
"xyz-2"
|
||||||
|
],
|
||||||
|
"used_data" : [ # optional
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt",
|
||||||
|
"extraction" : "./my-test.json"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
6. Lösung validieren lassen (`if "validate": true`)
|
||||||
|
- an (alle) "🤖 Lösung validieren" durch Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"riddle" : { ... }
|
||||||
|
"solution" : "26",
|
||||||
|
"explanation" : "x = 12, y = 14, ...",
|
||||||
|
"sub_riddles" : [ # optional
|
||||||
|
"xyz-1",
|
||||||
|
"xyz-2"
|
||||||
|
],
|
||||||
|
"used_data" : [ # optional
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"file" : "./my-test.txt",
|
||||||
|
"extraction" : "./my-test.json"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
7. Validierung annehmen (`if "validate": true`)
|
||||||
|
- von (alle) "🤖 Lösung validieren" an Management
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "xyz",
|
||||||
|
"solution" : "26",
|
||||||
|
"explanation" : "x = 12, y = 14, ...",
|
||||||
|
"accept" : false # or true
|
||||||
|
"review" : "y does not match Y"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
8. Ausgabe oder Wiedervorlage
|
||||||
|
- von Management an User oder als neues Riddle
|
||||||
|
- `if "accept" : false`: Neues Riddle mit `trial+1`, `solution_before`, `review_before`
|
||||||
|
- `if "accept" : true`: User bekommt `solution, explanation, review`
|
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
services:
|
||||||
|
management:
|
||||||
|
image: git.chai.uni-hamburg.de/ums-agenten/management:latest
|
||||||
|
ports:
|
||||||
|
-
|
||||||
|
environment:
|
||||||
|
- AGENTS_PROCESS=http://agent_process_1:3001,http://agent_process_2:3001
|
||||||
|
- AGENTS_SOLVE=http://agent_solve_1:3001
|
||||||
|
- AGENTS_GATEKEEPER=http://agent_gatekeeper_1:3001
|
||||||
|
volumes:
|
||||||
|
- /xxx/:
|
||||||
|
|
||||||
|
agent_process_1:
|
||||||
|
image: git.chai.uni-hamburg.de/ums-agenten/base-process:cpu
|
||||||
|
#image: git.chai.uni-hamburg.de/ums-agenten/base-process:gpu
|
||||||
|
build: .
|
||||||
|
environment:
|
||||||
|
- MANAGEMENT=http://management:3001
|
||||||
|
volumes:
|
||||||
|
- /xxx/:/ums-agenten/shared/
|
57
src/agent/agent.py
Normal file
57
src/agent/agent.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
from abc import abstractmethod
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
from o_types import *
|
||||||
|
|
||||||
|
class Agent():
|
||||||
|
|
||||||
|
def process_result():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# hier die Kommunikation mit dem Management Server
|
||||||
|
|
||||||
|
""" ===== """
|
||||||
|
|
||||||
|
class ProcessAgent(Agent):
|
||||||
|
TYPE:str = None
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def on_process_data(self, data:List[Data]):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TextAgentExample(ProcessAgent):
|
||||||
|
TYPE = Data.TYPE_TEXT
|
||||||
|
def on_process_data(self, data:List[Data]):
|
||||||
|
# Studi Code
|
||||||
|
self.process_result(Data(...))
|
||||||
|
|
||||||
|
class ImageAgentExample(ProcessAgent):
|
||||||
|
TYPE = Data.TYPE_IMAGE
|
||||||
|
|
||||||
|
class AudioAgentExample(ProcessAgent):
|
||||||
|
TYPE = Data.TYPE_AUDIO
|
||||||
|
|
||||||
|
""" ===== """
|
||||||
|
|
||||||
|
class SolveAgent(Agent):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def on_riddle_data(self, riddle:Riddle, data:List[Data]):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Studi Code
|
||||||
|
|
||||||
|
self.new_riddle(Riddle('x', 'y', 'z'))
|
||||||
|
self.send_riddle_result(...)
|
||||||
|
|
||||||
|
""" ===== """
|
||||||
|
|
||||||
|
class GatekeeperAgent(Agent):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def on_result_check(self, xyz):
|
||||||
|
|
||||||
|
# Studi Code
|
||||||
|
|
||||||
|
self.send_check_result(accept=True|False, ...)
|
80
src/agent/basic_agent.py
Normal file
80
src/agent/basic_agent.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
from agent import Agent
|
||||||
|
|
||||||
|
class ProcessTextAgent(Agent):
|
||||||
|
|
||||||
|
TYPE = "text" or "image"
|
||||||
|
|
||||||
|
|
||||||
|
def on_process_data(self, data:List[Dict]):
|
||||||
|
return filter(lambda x: x["type"] == self.TYPE, data)
|
||||||
|
|
||||||
|
# {type: "text", "file" : ""}
|
||||||
|
|
||||||
|
class ExampleAgent(ProcessTextAgent):
|
||||||
|
|
||||||
|
|
||||||
|
def on_process_data(self, data:List[Dict]):
|
||||||
|
# {type: "text", "file" : ""}
|
||||||
|
|
||||||
|
self.after_process_data(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# disk -> 123
|
||||||
|
# agent 1 disk -> 123
|
||||||
|
|
||||||
|
class Agent:
|
||||||
|
def request_management(self, request):
|
||||||
|
request.get(os.gentenv('MANAGEMENT'), data)
|
||||||
|
# https ...
|
||||||
|
|
||||||
|
def write_result(...):
|
||||||
|
self.request_management.write(...)
|
||||||
|
|
||||||
|
def read_result(...):
|
||||||
|
self.request_management.read(...)
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessAgent(Agent):
|
||||||
|
TYPE : str = None
|
||||||
|
|
||||||
|
def on_process_data(self, data:List[Dict]):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TextAgent(ProcessAgent):
|
||||||
|
TYPE = 'text'
|
||||||
|
text_data = self.on_process_data()
|
||||||
|
|
||||||
|
def on_process_data(self, data:List[Dict]):
|
||||||
|
text_data = filter_text_data()
|
||||||
|
processed_data = text_func1(text_data)
|
||||||
|
|
||||||
|
self.write_result(processed_data)
|
||||||
|
|
||||||
|
def text_func1():
|
||||||
|
...
|
||||||
|
|
||||||
|
def text_func2():
|
||||||
|
...
|
||||||
|
|
||||||
|
def text_func3():
|
||||||
|
...
|
||||||
|
|
||||||
|
class ImageAgent(ProcessAgent):
|
||||||
|
TYPE = 'image'
|
||||||
|
|
||||||
|
image_data = self.on_process_data()
|
||||||
|
|
||||||
|
|
||||||
|
def on_process_data(self, data:list[Dict])
|
||||||
|
image_data = filter_image_data()
|
||||||
|
|
||||||
|
def image_func1():
|
||||||
|
...
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
43
src/agent/o_types.py
Normal file
43
src/agent/o_types.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class Riddle():
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.id = "" # -> management.get_riddle_by_id(id)
|
||||||
|
self.parent_id = "" # ?!
|
||||||
|
|
||||||
|
self.context = "1234"
|
||||||
|
self.question = "12"
|
||||||
|
|
||||||
|
self.data:List[Data] = []
|
||||||
|
|
||||||
|
def from_json(json):
|
||||||
|
return Riddle(json)
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"context" : self.context,
|
||||||
|
"question" : self.question,
|
||||||
|
"solution_before" : "", # if trial > 0
|
||||||
|
"review_before": "" # if trial > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
class Data():
|
||||||
|
|
||||||
|
TYPE_TEXT = "text"
|
||||||
|
TYPE_AUDIO = "audio"
|
||||||
|
TYPE_IMAGE = "image"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.type = 1
|
||||||
|
self.file = 2
|
||||||
|
self.extraction = 3
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"type" : self.type,
|
||||||
|
"file" : self.file,
|
||||||
|
"extraction" : self.extraction
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user