Skip to content

Commit

Permalink
Merge pull request #432 from Aggregate-Intellect/event_logging
Browse files Browse the repository at this point in the history
Change event logging mechanism
  • Loading branch information
20001LastOrder authored Oct 11, 2024
2 parents 28f7a8c + 841b1d8 commit a7eb195
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/sherpa_ai/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from sherpa_ai.actions.utils.refinement import BaseRefinement
from sherpa_ai.actions.utils.reranking import BaseReranking
from sherpa_ai.events import EventType

if TYPE_CHECKING:
from sherpa_ai.memory.belief import Belief
Expand Down Expand Up @@ -132,13 +133,24 @@ def __call__(self, **kwargs):
"are 'agent' and 'belief'"
)

# Log to the belief
if self.belief is not None:
self.belief.update_internal(
EventType.action, self.name, f"Action: {self.name} starts, Args: {filtered_kwargs}"
)


# Execute the action
result = self.execute(**filtered_kwargs)

# Save the result to the belief
self.belief: Belief = self.belief
if self.belief:
self.belief.set(self.output_key, result)
self.belief.update_internal(
EventType.action_output, self.name, f"Action: {self.name} finishes, Observation: {result}"
)

return result

def __str__(self):
Expand Down
9 changes: 0 additions & 9 deletions src/sherpa_ai/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ def run(self):
f"🤖{self.name} is executing```" "``` {result.action.name}...```"
)

self.belief.update_internal(
EventType.action,
self.name,
"Action: " + result.action.name + str(result.args),
)

try:
action_output = self.act(result.action, result.args)
except Exception as e:
Expand All @@ -114,9 +108,6 @@ def run(self):

self.verbose_logger.log(f"```Action output: {action_output}```")
logger.debug(f"```Action output: {action_output}```")
self.belief.update_internal(
EventType.action_output, self.name, "Output: " + action_output
)

result = (
self.validate_output()
Expand Down
1 change: 1 addition & 0 deletions src/sherpa_ai/agents/qa_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def create_actions(self) -> List[BaseAction]:
task=self.belief.current_task.content,
llm=self.llm,
config=self.config,
belief=self.belief,
),
]

Expand Down
Loading

0 comments on commit a7eb195

Please sign in to comment.