Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: added token counter command to CLI (#2047)
Charles Packer7f8e91103843
diff --git a/letta/agent.py b/letta/agent.pyindex f7bd6f0fb..455d9eedc 100644--- a/letta/agent.py+++ b/letta/agent.py@@ -1582,6 +1582,10 @@ class Agent(BaseAgent):functions_definitions=available_functions_definitions,)+ def count_tokens(self) -> int:+ """Count the tokens in the current context window"""+ return self.get_context_window().context_window_size_current+def save_agent(agent: Agent, ms: MetadataStore):"""Save agent to metadata store"""diff --git a/letta/main.py b/letta/main.pyindex 70595d6c8..abfd36ae9 100644--- a/letta/main.py+++ b/letta/main.py@@ -254,6 +254,15 @@ def run_agent_loop()continue+ elif user_input.lower() == "/tokens":+ tokens = letta_agent.count_tokens()+ typer.secho(+ f"{tokens}/{letta_agent.agent_state.llm_config.context_window}",+ fg=typer.colors.GREEN,+ bold=True,+ )+ continue+elif user_input.lower().startswith("/add_function"):try:if len(user_input) < len("/add_function "):