Rename fields in agent metadata (#336)

* Rename fields in agent metadata

* team one fixes

* another fix
This commit is contained in:
Jack Gerrits
2024-08-07 16:08:13 -04:00
committed by GitHub
parent 437dbefc32
commit 39489ba395
32 changed files with 94 additions and 95 deletions

View File

@@ -94,7 +94,7 @@ class TeamOneBaseAgent(TypeRoutedAgent):
self._enabled = False
logger.info(
AgentEvent(
f"{self.metadata['name']} (deactivated)",
f"{self.metadata['type']} (deactivated)",
"",
)
)

View File

@@ -40,7 +40,7 @@ class BaseOrchestrator(TeamOneBaseAgent):
if self._num_rounds >= self._max_rounds:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (termination condition)",
f"{self.metadata['type']} (termination condition)",
f"Max rounds ({self._max_rounds}) reached.",
)
)
@@ -49,7 +49,7 @@ class BaseOrchestrator(TeamOneBaseAgent):
if message.request_halt:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (termination condition)",
f"{self.metadata['type']} (termination condition)",
f"{source} requested halt.",
)
)
@@ -59,7 +59,7 @@ class BaseOrchestrator(TeamOneBaseAgent):
if next_agent is None:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (termination condition)",
f"{self.metadata['type']} (termination condition)",
"No agent selected.",
)
)
@@ -69,8 +69,8 @@ class BaseOrchestrator(TeamOneBaseAgent):
logger.info(
OrchestrationEvent(
source=f"{self.metadata['name']} (thought)",
message=f"Next speaker {(await next_agent.metadata)['name']}" "",
source=f"{self.metadata['type']} (thought)",
message=f"Next speaker {(await next_agent.metadata)['type']}" "",
)
)

View File

@@ -41,10 +41,10 @@ class BaseWorker(TeamOneBaseAgent):
"""Respond to a reply request."""
request_halt, response = await self._generate_reply(cancellation_token)
assistant_message = AssistantMessage(content=message_content_to_str(response), source=self.metadata["name"])
assistant_message = AssistantMessage(content=message_content_to_str(response), source=self.metadata["type"])
self._chat_history.append(assistant_message)
user_message = UserMessage(content=response, source=self.metadata["name"])
user_message = UserMessage(content=response, source=self.metadata["type"])
await self.publish_message(BroadcastMessage(content=user_message, request_halt=request_halt))
async def _generate_reply(self, cancellation_token: CancellationToken) -> Tuple[bool, UserContent]:

View File

@@ -211,7 +211,7 @@ setInterval(function() {{
await self._page.screenshot(path=os.path.join(self.debug_dir, "screenshot.png"))
logger.info(
WebSurferEvent(
source=self.metadata["name"],
source=self.metadata["type"],
url=self._page.url,
message="Resetting browser.",
)
@@ -262,7 +262,7 @@ setInterval(function() {{
assert self._page is not None
logger.info(
WebSurferEvent(
source=self.metadata["name"],
source=self.metadata["type"],
url=self._page.url,
action=name,
arguments=args,
@@ -519,7 +519,7 @@ When deciding between tools, consider if the request can be best addressed by:
# Add the multimodal message and make the request
history.append(
UserMessage(content=[text_prompt, AGImage.from_pil(scaled_screenshot)], source=self.metadata["name"])
UserMessage(content=[text_prompt, AGImage.from_pil(scaled_screenshot)], source=self.metadata["type"])
)
response = await self._model_client.create(
history, tools=tools, extra_create_args={"tool_choice": "auto"}
@@ -674,7 +674,7 @@ When deciding between tools, consider if the request can be best addressed by:
logger.info(
WebSurferEvent(
source=self.metadata["name"],
source=self.metadata["type"],
url=self._page.url,
message="New tab or window.",
)
@@ -758,7 +758,7 @@ When deciding between tools, consider if the request can be best addressed by:
prompt + buffer + line,
# ag_image,
# ],
source=self.metadata["name"],
source=self.metadata["type"],
)
remaining = self._model_client.remaining_tokens(messages + [message])
@@ -779,7 +779,7 @@ When deciding between tools, consider if the request can be best addressed by:
prompt + buffer,
ag_image,
],
source=self.metadata["name"],
source=self.metadata["type"],
)
)
@@ -811,7 +811,7 @@ When deciding between tools, consider if the request can be best addressed by:
"Please transcribe all visible text on this page, including both main content and the labels of UI elements.",
AGImage.from_pil(scaled_screenshot),
],
source=self.metadata["name"],
source=self.metadata["type"],
)
)
response = await self._model_client.create(messages)

View File

@@ -83,13 +83,13 @@ class LedgerOrchestrator(BaseOrchestrator):
team_description = ""
for agent in self._agents:
metadata = await agent.metadata
name = metadata["name"]
name = metadata["type"]
description = metadata["description"]
team_description += f"{name}: {description}\n"
return team_description
async def _get_team_names(self) -> List[str]:
return [(await agent.metadata)["name"] for agent in self._agents]
return [(await agent.metadata)["type"] for agent in self._agents]
def _set_task_str(self, message: LLMMessage) -> None:
if len(self._chat_history) == 1:
@@ -119,18 +119,18 @@ class LedgerOrchestrator(BaseOrchestrator):
# create a closed book task and generate a response and update the chat history
cb_task = self._get_closed_book_prompt(self.task_str)
cb_user_message = UserMessage(
content=cb_task, source=self.metadata["name"]
content=cb_task, source=self.metadata["type"]
) # TODO: allow images in this message.
cb_response = await self._model_client.create(self._system_messages + self._chat_history + [cb_user_message])
facts = cb_response.content
assert isinstance(facts, str)
cb_assistant_message = AssistantMessage(content=facts, source=self.metadata["name"])
cb_assistant_message = AssistantMessage(content=facts, source=self.metadata["type"])
# 2. CREATE A PLAN
## plan based on available information
plan_task = self._get_plan_prompt(self.task_str, team_description)
plan_user_message = UserMessage(
content=plan_task, source=self.metadata["name"]
content=plan_task, source=self.metadata["type"]
) # TODO: allow images in this message.
plan_response = await self._model_client.create(
self._system_messages + self._chat_history + [cb_assistant_message, plan_user_message]
@@ -148,7 +148,7 @@ class LedgerOrchestrator(BaseOrchestrator):
team_description = await self._get_team_description()
names = await self._get_team_names()
ledger_prompt = self._get_ledger_prompt(self.task_str, team_description, names)
ledger_user_message = UserMessage(content=ledger_prompt, source=self.metadata["name"])
ledger_user_message = UserMessage(content=ledger_prompt, source=self.metadata["type"])
assert max_json_retries > 0
for _ in range(max_json_retries):
@@ -165,7 +165,7 @@ class LedgerOrchestrator(BaseOrchestrator):
except json.JSONDecodeError as e:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (error)",
f"{self.metadata['type']} (error)",
f"Failed to parse ledger information: {ledger_str}",
)
)
@@ -180,10 +180,10 @@ class LedgerOrchestrator(BaseOrchestrator):
if self._should_replan:
plan_str = await self._plan()
plan_user_message = UserMessage(content=plan_str, source=self.metadata["name"])
plan_user_message = UserMessage(content=plan_str, source=self.metadata["type"])
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (thought)",
f"{self.metadata['type']} (thought)",
f"New plan:\n{plan_str}",
)
)
@@ -196,7 +196,7 @@ class LedgerOrchestrator(BaseOrchestrator):
ledger_dict = await self.update_ledger()
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (thought)",
f"{self.metadata['type']} (thought)",
f"Updated Ledger:\n{json.dumps(ledger_dict, indent=2)}",
)
)
@@ -204,7 +204,7 @@ class LedgerOrchestrator(BaseOrchestrator):
if ledger_dict["is_request_satisfied"]["answer"] is True:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (thought)",
f"{self.metadata['type']} (thought)",
"Request satisfied.",
)
)
@@ -219,7 +219,7 @@ class LedgerOrchestrator(BaseOrchestrator):
if self._replan_counter < self._max_replans:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (thought)",
f"{self.metadata['type']} (thought)",
"Stalled.... Replanning...",
)
)
@@ -227,7 +227,7 @@ class LedgerOrchestrator(BaseOrchestrator):
else:
logger.info(
OrchestrationEvent(
f"{self.metadata['name']} (thought)",
f"{self.metadata['type']} (thought)",
"Replan counter exceeded... Terminating.",
)
)
@@ -235,11 +235,11 @@ class LedgerOrchestrator(BaseOrchestrator):
next_agent_name = ledger_dict["next_speaker"]["answer"]
for agent in self._agents:
if (await agent.metadata)["name"] == next_agent_name:
if (await agent.metadata)["type"] == next_agent_name:
# broadcast a new message
instruction = ledger_dict["instruction_or_question"]["answer"]
user_message = UserMessage(content=instruction, source=self.metadata["name"])
logger.info(OrchestrationEvent(f"{self.metadata['name']} (-> {next_agent_name})", instruction))
user_message = UserMessage(content=instruction, source=self.metadata["type"])
logger.info(OrchestrationEvent(f"{self.metadata['type']} (-> {next_agent_name})", instruction))
await self.publish_message(BroadcastMessage(content=user_message, request_halt=False))
return agent

View File

@@ -18,7 +18,7 @@ class ReflexAgent(TypeRoutedAgent):
async def handle_request_reply_message(
self, message: RequestReplyMessage, cancellation_token: CancellationToken
) -> None:
name = self.metadata["name"]
name = self.metadata["type"]
response_message = UserMessage(
content=f"Hello, world from {name}!",