Merge remote-tracking branch 'origin/feat/extra-agentspeak-functionality' into feat/monitoringpage-cb
This commit is contained in:
@@ -86,6 +86,7 @@ class BDIProgramManager(BaseAgent):
|
||||
self._phase = phase
|
||||
|
||||
self._send_beliefs_to_semantic_belief_extractor()
|
||||
self._send_goals_to_semantic_belief_extractor()
|
||||
|
||||
# Notify user interaction agent
|
||||
msg = InternalMessage(
|
||||
@@ -132,12 +133,10 @@ class BDIProgramManager(BaseAgent):
|
||||
|
||||
await self.send(message)
|
||||
|
||||
@staticmethod
|
||||
def _extract_goals_from_program(program: Program) -> list[Goal]:
|
||||
def _extract_current_goals(self) -> list[Goal]:
|
||||
"""
|
||||
Extract all goals from the program, including subgoals.
|
||||
|
||||
:param program: The program received from the API.
|
||||
:return: A list of Goal objects.
|
||||
"""
|
||||
goals: list[Goal] = []
|
||||
@@ -149,19 +148,16 @@ class BDIProgramManager(BaseAgent):
|
||||
goals_.extend(extract_goals_from_goal(plan))
|
||||
return goals_
|
||||
|
||||
for phase in program.phases:
|
||||
for goal in phase.goals:
|
||||
goals.extend(extract_goals_from_goal(goal))
|
||||
for goal in self._phase.goals:
|
||||
goals.extend(extract_goals_from_goal(goal))
|
||||
|
||||
return goals
|
||||
|
||||
async def _send_goals_to_semantic_belief_extractor(self, program: Program):
|
||||
async def _send_goals_to_semantic_belief_extractor(self):
|
||||
"""
|
||||
Extract goals from the program and send them to the Semantic Belief Extractor Agent.
|
||||
|
||||
:param program: The program received from the API.
|
||||
Extract goals for the current phase and send them to the Semantic Belief Extractor Agent.
|
||||
"""
|
||||
goals = GoalList(goals=self._extract_goals_from_program(program))
|
||||
goals = GoalList(goals=self._extract_current_goals())
|
||||
|
||||
message = InternalMessage(
|
||||
to=settings.agent_settings.text_belief_extractor_name,
|
||||
@@ -172,12 +168,34 @@ class BDIProgramManager(BaseAgent):
|
||||
|
||||
await self.send(message)
|
||||
|
||||
async def _send_clear_llm_history(self):
|
||||
"""
|
||||
Clear the LLM Agent's conversation history.
|
||||
|
||||
Sends an empty history to the LLM Agent to reset its state.
|
||||
"""
|
||||
message = InternalMessage(
|
||||
to=settings.agent_settings.llm_name,
|
||||
body="clear_history",
|
||||
)
|
||||
await self.send(message)
|
||||
self.logger.debug("Sent message to LLM agent to clear history.")
|
||||
|
||||
extractor_msg = InternalMessage(
|
||||
to=settings.agent_settings.text_belief_extractor_name,
|
||||
thread="conversation_history",
|
||||
body="reset",
|
||||
)
|
||||
await self.send(extractor_msg)
|
||||
self.logger.debug("Sent message to extractor agent to clear history.")
|
||||
|
||||
async def _receive_programs(self):
|
||||
"""
|
||||
Continuous loop that receives program updates from the HTTP endpoint.
|
||||
|
||||
It listens to the ``program`` topic on the internal ZMQ SUB socket.
|
||||
When a program is received, it is validated and forwarded to BDI via :meth:`_send_to_bdi`.
|
||||
Additionally, the LLM history is cleared via :meth:`_send_clear_llm_history`.
|
||||
"""
|
||||
while True:
|
||||
topic, body = await self.sub_socket.recv_multipart()
|
||||
@@ -190,10 +208,12 @@ class BDIProgramManager(BaseAgent):
|
||||
|
||||
self._initialize_internal_state(program)
|
||||
|
||||
await self._send_clear_llm_history()
|
||||
|
||||
await asyncio.gather(
|
||||
self._create_agentspeak_and_send_to_bdi(program),
|
||||
self._send_beliefs_to_semantic_belief_extractor(),
|
||||
self._send_goals_to_semantic_belief_extractor(program),
|
||||
self._send_goals_to_semantic_belief_extractor(),
|
||||
)
|
||||
|
||||
async def setup(self):
|
||||
|
||||
@@ -116,9 +116,19 @@ class TextBeliefExtractorAgent(BaseAgent):
|
||||
self._handle_beliefs_message(msg)
|
||||
case "goals":
|
||||
self._handle_goals_message(msg)
|
||||
case "conversation_history":
|
||||
if msg.body == "reset":
|
||||
self._reset()
|
||||
case _:
|
||||
self.logger.warning("Received unexpected message from %s", msg.sender)
|
||||
|
||||
def _reset(self):
|
||||
self.conversation = ChatHistory(messages=[])
|
||||
self.belief_inferrer.available_beliefs.clear()
|
||||
self._current_beliefs = BeliefState()
|
||||
self.goal_inferrer.goals.clear()
|
||||
self._current_goal_completions = {}
|
||||
|
||||
def _handle_beliefs_message(self, msg: InternalMessage):
|
||||
try:
|
||||
belief_list = BeliefList.model_validate_json(msg.body)
|
||||
|
||||
Reference in New Issue
Block a user