-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
62 lines (51 loc) · 2.1 KB
/
agent.py
File metadata and controls
62 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import base64
from a2a.server.tasks import TaskUpdater
from a2a.types import (DataPart, FilePart, FileWithBytes, Message, Part,
TaskState, TextPart)
from a2a.utils import new_agent_text_message
from messenger import Messenger
class Agent:
def __init__(self):
self.messenger = Messenger()
# Initialize other state here
async def run(self, message: Message, updater: TaskUpdater) -> None:
"""Implement your agent logic here.
Args:
message: The incoming message
updater: Report progress (update_status) and results (add_artifact)
Use self.messenger.talk_to_agent(message, url) to call other agents.
"""
# Replace this example code with your agent logic
await updater.update_status(
TaskState.working, new_agent_text_message("Thinking...")
)
# Unpack parts sent by A2AClientAgent
instruction = ""
obs: dict = {}
env_config: dict = {}
for part in message.parts:
root = part.root
if isinstance(root, TextPart):
instruction = root.text
print(f"instruction: {instruction}")
elif isinstance(root, FilePart):
if isinstance(root.file, FileWithBytes):
obs["screenshot"] = base64.b64decode(root.file.bytes)
print(f" obs[screenshot]: {len(obs['screenshot'])} bytes")
elif isinstance(root, DataPart):
if "env_config" in root.data:
env_config = root.data["env_config"]
print(f"env_config: {env_config!r}")
else:
obs.update(root.data)
for key, val in root.data.items():
print(f" obs[{key}]: {val!r}")
response = "dummy agent doing nothing"
actions = ["DONE"]
await updater.add_artifact(
parts=[
Part(root=TextPart(text=response)),
Part(root=DataPart(data={"actions": actions})),
],
name="prediction",
)