Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Changes with_tracker signature and LocalTracker

Stefan Krawczyk908ab9c34b1f
diff --git a/burr/core/application.py b/burr/core/application.py
index 71173e41..2eaab3f3 100644
--- a/burr/core/application.py
+++ b/burr/core/application.py
@@ -33,7 +33,13 @@ from burr.core.action import (
default,
)
from burr.core.state import BasicStatePersistence, State
-from burr.lifecycle import PostRunStepHook
+from burr.lifecycle import (
+ PostApplicationCreateHook,
+ PostEndSpanHook,
+ PostRunStepHook,
+ PreRunStepHook,
+ PreStartSpanHook,
+)
from burr.lifecycle.base import LifecycleAdapter
from burr.lifecycle.internal import LifecycleAdapterSet
@@ -1085,7 +1091,7 @@ class ApplicationBuilder:
self.lifecycle_adapters: List[LifecycleAdapter] = list()
self.app_id: str = str(uuid.uuid4())
self.partition_key: str = None
- self.sequence_id: int = None
+ self.sequence_id: int = 0
self.persister = None
self.use_entrypoint_from_save_state: bool = None
self.default_state: dict = None
@@ -1186,28 +1192,43 @@ class ApplicationBuilder:
return self
def with_tracker(
- self, project: str, tracker: Literal["local"] = "local", params: Dict[str, Any] = None
+ self,
+ tracker: Union[Literal["local"], object] = "local",
+ project: str = "default",
+ params: Dict[str, Any] = None,
):
"""Adds a "tracker" to the application. The tracker specifies
a project name (used for disambiguating groups of tracers), and plugs into the
Burr UI. Currently the only supported tracker is local, which takes in the params
`storage_dir` and `app_id`, which have automatic defaults.
- :param project: Project name
- :param tracker: Tracker to use, currently only ``local`` is available
- :param params: Parameters to pass to the tracker
+ :param tracker: Tracker to use. ``local`` creates one, else pass one in.
+ :param project: Project name -- used if the tracker is local.
+ :param params: Parameters to pass to the tracker if it's local.
:return: The application builder for future chaining.
"""
if params is None:
params = {}
- if tracker == "local":
+ # if it's a lifecycle adapter, just add it
+ if isinstance(
+ tracker,
+ (
+ PostRunStepHook,
+ PreRunStepHook,
+ PostApplicationCreateHook,
+ PostEndSpanHook,
+ PreStartSpanHook,
+ ),
+ ):
+ self.lifecycle_adapters.append(tracker)
+ elif tracker == "local":
from burr.tracking.client import LocalTrackingClient
kwargs = {"project": project, "app_id": self.app_id}
kwargs.update(params)
self.lifecycle_adapters.append(LocalTrackingClient(**kwargs))
else:
- raise ValueError(f"Tracker {tracker} not supported")
+ raise ValueError(f"Tracker {tracker}:{project} not supported")
return self
def initialize_from(
diff --git a/burr/core/state.py b/burr/core/state.py
index 777b0e4b..b70b409f 100644
--- a/burr/core/state.py
+++ b/burr/core/state.py
@@ -268,7 +268,7 @@ class BasicStatePersistence(abc.ABC):
class SQLLitePersistence(BasicStatePersistence):
- """Class for SQLLite persistence of state. This is a simple implementation that uses SQLLite."""
+ """Class for SQLLite persistence of state. This is a simple implementation."""
def __init__(self, db_path: str, table_name: str = "burr_state"):
"""Constructor
diff --git a/burr/lifecycle/__init__.py b/burr/lifecycle/__init__.py
index 25e31ead..038416db 100644
--- a/burr/lifecycle/__init__.py
+++ b/burr/lifecycle/__init__.py
@@ -1,5 +1,7 @@
from burr.lifecycle.base import (
LifecycleAdapter,
+ PostApplicationCreateHook,
+ PostEndSpanHook,
PostRunApplicationHook,
PostRunApplicationHookAsync,
PostRunStepHook,
@@ -8,6 +10,7 @@ from burr.lifecycle.base import (
PreRunApplicationHookAsync,
PreRunStepHook,
PreRunStepHookAsync,
+ PreStartSpanHook,
)
from burr.lifecycle.default import StateAndResultsFullLogger
@@ -22,4 +25,7 @@ __all__ = [
"PostRunApplicationHookAsync",
"LifecycleAdapter",
"StateAndResultsFullLogger",
+ "PostApplicationCreateHook",
+ "PostEndSpanHook",
+ "PreStartSpanHook",
]
diff --git a/burr/tracking/client.py b/burr/tracking/client.py
index 83c7f22b..8c2d0583 100644
--- a/burr/tracking/client.py
+++ b/burr/tracking/client.py
@@ -4,12 +4,18 @@ import logging
import os
import traceback
import uuid
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Literal, Optional
from burr.core import Action, ApplicationGraph, State
+from burr.core.state import BasicStatePersistence, PersistenceDict
from burr.integrations.base import require_plugin
-from burr.lifecycle import PostRunStepHook, PreRunStepHook
-from burr.lifecycle.base import PostApplicationCreateHook, PostEndSpanHook, PreStartSpanHook
+from burr.lifecycle import (
+ PostApplicationCreateHook,
+ PostEndSpanHook,
+ PostRunStepHook,
+ PreRunStepHook,
+ PreStartSpanHook,
+)
from burr.tracking.common.models import (
ApplicationModel,
BeginEntryModel,
@@ -43,6 +49,7 @@ class LocalTrackingClient(
PostRunStepHook,
PreStartSpanHook,
PostEndSpanHook,
+ BasicStatePersistence,
):
"""Tracker to track locally -- goes along with the Burr UI. Writes
down the following:
@@ -237,6 +244,32 @@ class LocalTrackingClient(
def __del__(self):
self.f.close()
+ def initialize(self):
+ # not needed because this one does things in the constructor
+ pass
+
+ def list_app_ids(self, partition_key: str) -> list[str]:
+ # TODO:
+ return []
+
+ def load(
+ self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None
+ ) -> Optional[PersistenceDict]:
+ # TODO:
+ pass
+
+ def save(
+ self,
+ partition_key: Optional[str],
+ app_id: str,
+ sequence_id: int,
+ position: str,
+ state: State,
+ status: Literal["completed", "failed"],
+ ):
+ # TODO:
+ pass
+
# TODO -- implement async version
# class AsyncTrackingClient(PreRunStepHookAsync, PostRunStepHookAsync, PostApplicationCreateHook):
diff --git a/examples/conversational_rag/application.py b/examples/conversational_rag/application.py
index f58bb6eb..0c95042c 100644
--- a/examples/conversational_rag/application.py
+++ b/examples/conversational_rag/application.py
@@ -95,7 +95,7 @@ def application(
)
.with_entrypoint("human_converse")
.with_tracker(
- "demo:conversational-rag", params={"app_id": app_id, "storage_dir": storage_dir}
+ project="demo:conversational-rag", params={"app_id": app_id, "storage_dir": storage_dir}
)
.with_hooks(*hooks if hooks else [])
.build()
diff --git a/examples/corgi_adventure/application.py b/examples/corgi_adventure/application.py
index 0230474c..ece9910c 100644
--- a/examples/corgi_adventure/application.py
+++ b/examples/corgi_adventure/application.py
@@ -127,7 +127,9 @@ def application(
("maybe_progress", "prompt_for_challenge", default),
)
.with_entrypoint("start")
- .with_tracker("demo:corgi_adventure", params={"app_id": app_id, "storage_dir": storage_dir})
+ .with_tracker(
+ project="demo:corgi_adventure", params={"app_id": app_id, "storage_dir": storage_dir}
+ )
.build()
)
diff --git a/examples/counter/application.py b/examples/counter/application.py
index 5ea04381..19619ce0 100644
--- a/examples/counter/application.py
+++ b/examples/counter/application.py
@@ -47,7 +47,7 @@ def application(
default_entry_point="counter",
)
.with_state_persister(persister)
- .with_tracker("demo:counter", params={"storage_dir": storage_dir})
+ .with_tracker(project="demo:counter", params={"storage_dir": storage_dir})
.with_hooks(*hooks if hooks else [])
.build()
)
diff --git a/examples/gpt/application.py b/examples/gpt/application.py
index 9dc60d82..130b81ee 100644
--- a/examples/gpt/application.py
+++ b/examples/gpt/application.py
@@ -165,7 +165,7 @@ def base_application(hooks: List[LifecycleAdapter], app_id: str, storage_dir: st
("response", "prompt", default),
)
.with_hooks(*hooks)
- .with_tracker("demo:chatbot", params={"app_id": app_id, "storage_dir": storage_dir})
+ .with_tracker(project="demo:chatbot", params={"app_id": app_id, "storage_dir": storage_dir})
.build()
)
@@ -231,7 +231,7 @@ def hamilton_application(hooks: List[LifecycleAdapter], app_id: str, storage_dir
("response", "prompt", default),
)
.with_hooks(*hooks)
- .with_tracker("demo:chatbot", params={"app_id": app_id, "storage_dir": storage_dir})
+ .with_tracker(project="demo:chatbot", params={"app_id": app_id, "storage_dir": storage_dir})
.build()
)
return application
diff --git a/examples/gpt/application_with_traces.py b/examples/gpt/application_with_traces.py
index 99196fb6..f8f5ee91 100644
--- a/examples/gpt/application_with_traces.py
+++ b/examples/gpt/application_with_traces.py
@@ -190,7 +190,7 @@ def base_application(hooks: List[LifecycleAdapter], app_id: str, storage_dir: st
("response", "prompt", default),
)
.with_hooks(*hooks)
- .with_tracker("demo:tracing", params={"app_id": app_id, "storage_dir": storage_dir})
+ .with_tracker(project="demo:tracing", params={"app_id": app_id, "storage_dir": storage_dir})
.build()
)
diff --git a/examples/image_telephone/application.py b/examples/image_telephone/application.py
index accd3dfc..599d2400 100644
--- a/examples/image_telephone/application.py
+++ b/examples/image_telephone/application.py
@@ -81,7 +81,7 @@ def regular_action_main():
)
.with_entrypoint("caption")
.with_hooks(PrintStepHook())
- .with_tracker("image-telephone")
+ .with_tracker(project="image-telephone")
.build()
)
return app
@@ -126,7 +126,7 @@ def hamilton_action_main():
)
.with_entrypoint("caption")
.with_hooks(PrintStepHook())
- .with_tracker("image-telephone")
+ .with_tracker(project="image-telephone")
.build()
)
return app
diff --git a/examples/multi-agent-collaboration/application.py b/examples/multi-agent-collaboration/application.py
index 2aab9968..cfb459b3 100644
--- a/examples/multi-agent-collaboration/application.py
+++ b/examples/multi-agent-collaboration/application.py
@@ -147,7 +147,7 @@ def main(app_instance_id: str = None):
)
.with_entrypoint(entry_point)
.with_hooks(PrintStepHook())
- .with_tracker(project_name)
+ .with_tracker(project=project_name)
.build()
)
app.visualize(
diff --git a/examples/multi-agent-collaboration/hamilton_application.py b/examples/multi-agent-collaboration/hamilton_application.py
index 433c7460..fc9583cd 100644
--- a/examples/multi-agent-collaboration/hamilton_application.py
+++ b/examples/multi-agent-collaboration/hamilton_application.py
@@ -178,7 +178,7 @@ def main(app_instance_id: str = None):
)
.with_entrypoint(entry_point)
.with_hooks(PrintStepHook())
- .with_tracker(project_name)
+ .with_tracker(project=project_name)
.build()
)
app.visualize(
diff --git a/examples/multi-agent-collaboration/lcel_application.py b/examples/multi-agent-collaboration/lcel_application.py
index 77ae7130..7bba6107 100644
--- a/examples/multi-agent-collaboration/lcel_application.py
+++ b/examples/multi-agent-collaboration/lcel_application.py
@@ -190,7 +190,7 @@ def main(app_instance_id: str = None):
)
.with_entrypoint(entry_point)
.with_hooks(PrintStepHook())
- .with_tracker("demo:lcel-multi-agent")
+ .with_tracker(project="demo:lcel-multi-agent")
.build()
)
app.visualize(
diff --git a/examples/streaming_chatbot/application.py b/examples/streaming_chatbot/application.py
index 301b7bff..cc4a6dd5 100644
--- a/examples/streaming_chatbot/application.py
+++ b/examples/streaming_chatbot/application.py
@@ -169,7 +169,7 @@ def application(hooks: List[LifecycleAdapter], app_id: Optional[str] = None):
),
)
.with_hooks(*hooks)
- .with_tracker("demo:chatbot_streaming", params={"app_id": app_id})
+ .with_tracker(project="demo:chatbot_streaming", params={"app_id": app_id})
.build()
)
diff --git a/tests/tracking/test_local_tracking_client.py b/tests/tracking/test_local_tracking_client.py
index e7ce8ee5..ca5cce43 100644
--- a/tests/tracking/test_local_tracking_client.py
+++ b/tests/tracking/test_local_tracking_client.py
@@ -38,7 +38,7 @@ def sample_application(project_name: str, log_dir: str, app_id: str, broken: boo
)
.with_entrypoint("counter")
.with_tracker(
- project_name, tracker="local", params={"storage_dir": log_dir, "app_id": app_id}
+ project=project_name, tracker="local", params={"storage_dir": log_dir, "app_id": app_id}
)
.build()
)