Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Shows prototype how to load from tracked state
Stefan Krawczyk0441b7917569
diff --git a/burr/tracking/server/backend.py b/burr/tracking/server/backend.pyindex 8dfd9e08..fdc3e0de 100644--- a/burr/tracking/server/backend.py+++ b/burr/tracking/server/backend.py@@ -101,6 +101,9 @@ class LocalBackend(BackendBase):raise fastapi.HTTPException(status_code=404, detail=f"Project: {project_id} not found")out = []for entry in await aiofilesos.listdir(project_filepath):+ if entry.startswith("."):+ # skip hidden files/directories+ continuefull_path = os.path.join(project_filepath, entry)log_path = os.path.join(full_path, "log.jsonl")if os.path.isdir(full_path):diff --git a/examples/multi-agent-collaboration/application.py b/examples/multi-agent-collaboration/application.pyindex e48bfd37..fa11d924 100644--- a/examples/multi-agent-collaboration/application.py+++ b/examples/multi-agent-collaboration/application.py@@ -1,3 +1,6 @@+import json+import os.path+import func_agentfrom langchain_community.tools.tavily_search import TavilySearchResultsfrom langchain_experimental.utilities import PythonREPL@@ -123,16 +126,46 @@ class PrintStepHook(PostRunStepHook):print("state======\n", state)-def main():+def initialize_state_from_logs(tracker_name: str, app_id: str) -> tuple[dict, str]:+ """Initialize the state to debug from an exception++ :param tracker_name:+ :param app_id:+ :return:+ """+ # open ~/.burr/{tracker_name}/{app_id}/log.jsonl+ # find the first entry with an exception -- and pull state from it.+ with open(f"{os.path.expanduser('~/')}/.burr/{tracker_name}/{app_id}/log.jsonl", "r") as f:+ lines = f.readlines()+ for line in lines:+ line = json.loads(line)+ if "exception" in line:+ state = line["state"]+ entry_point = line["action"]+ return state, entry_point+ raise ValueError(f"No exception found in logs for {tracker_name}/{app_id}")+++def default_state_and_entry_point() -> tuple[dict, str]:+ return {+ "messages": [],+ "query": "Fetch the UK's GDP over the past 5 years,"+ " then draw a line graph of it."+ " Once you code it up, finish.",+ "next_hop": "",+ }, "researcher"+++def main(app_instance_id: str = None):+ tracker_name = "hamilton-multi-agent"+ if app_instance_id:+ state, entry_point = initialize_state_from_logs(tracker_name, app_instance_id)+ else:+ state, entry_point = default_state_and_entry_point()+app = (ApplicationBuilder()- .with_state(- messages=[],- query="Fetch the UK's GDP over the past 5 years,"- " then draw a line graph of it."- " Once you code it up, finish.",- next_hop="",- )+ .with_state(**state).with_actions(researcher=researcher,chart_generator=chart_generator,@@ -154,9 +187,9 @@ def main():core.expr("next_hop == 'complete'"),), # core.expr("'FINAL ANSWER' in messages[-1]['content']")),)- .with_entrypoint("researcher")+ .with_entrypoint(entry_point).with_hooks(PrintStepHook())- .with_tracker("hamilton-multi-agent")+ .with_tracker(tracker_name).build())app.run(halt_after=["terminal"])@@ -164,7 +197,8 @@ def main():if __name__ == "__main__":- main()+ _app_id = "app_4d1618d2-79d1-4d89-8e3f-70c216c71e63"+ main(_app_id)import syssys.exit(0)