Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor agent interface a bit #74

Merged
merged 11 commits into from
Mar 21, 2024
Prev Previous commit
Next Next commit
fix init
  • Loading branch information
rbren committed Mar 21, 2024
commit 3a2c93d1b18b7b7bd40fe19560cad9ee98d6afbf
37 changes: 22 additions & 15 deletions agenthub/langchains_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,28 @@ def _initialize(self):
if self._initialized:
return
self.agent = LangchainsAgentImpl(self.instruction)
# TODO: make it add a Message to the history for each turn / event
for i in range(max_iterations):
print("STEP", i, flush=True)
log_events = agent.get_background_logs()
for event in log_events:
print(event, flush=True)
action = agent.get_next_action()
if action.action == "finish":
print("Done!", flush=True)
break
print(action, flush=True)
print("---", flush=True)
out = agent.maybe_perform_latest_action()
print(out, flush=True)
print("==============", flush=True)
next_is_output = False
for thought in INITIAL_THOUGHTS:
thought = thought.replace("$TASK", self.instruction)
if next_is_output:
event = Event("output", {"output": thought})
next_is_output = False
else:
if thought.startswith("RUN"):
command = thought.split("RUN ")[1]
event = Event("run", {"command": command})
next_is_output = True
elif thought.startswith("RECALL"):
query = thought.split("RECALL ")[1]
event = Event("recall", {"query": query})
next_is_output = True
elif thought.startswith("BROWSE"):
url = thought.split("BROWSE ")[1]
event = Event("browse", {"url": url})
next_is_output = True
else:
event = Event("think", {"thought": thought})
agent.add_event(event)

def add_event(self, event: Event) -> None:
self.agent.add_event(event)
Expand Down