recall-livekit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- recall_livekit/__init__.py +41 -0
- recall_livekit/agent.py +101 -0
- recall_livekit/hooks.py +91 -0
- recall_livekit/memory.py +248 -0
- recall_livekit/py.typed +0 -0
- recall_livekit/registry_voice.json +57 -0
- recall_livekit/render.py +74 -0
- recall_livekit/tools.py +139 -0
- recall_livekit-0.1.0.dist-info/METADATA +168 -0
- recall_livekit-0.1.0.dist-info/RECORD +12 -0
- recall_livekit-0.1.0.dist-info/WHEEL +4 -0
- recall_livekit-0.1.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Recall by Polign for LiveKit Agents.
|
|
2
|
+
|
|
3
|
+
One ``RecallMemory`` per worker process owns the Recall subprocess. Each
|
|
4
|
+
caller gets a ``SubjectMemory`` view on it, and ``RecallAgent`` (or ``attach``
|
|
5
|
+
for an existing Agent subclass) loads that caller's facts before the first
|
|
6
|
+
reply and exposes a ``remember`` tool so the model can store new ones.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from importlib import resources
|
|
10
|
+
|
|
11
|
+
from .agent import RecallAgent
|
|
12
|
+
from .hooks import MemoryBinding, attach
|
|
13
|
+
from .memory import PredicateSpec, RecallMemory, SubjectMemory
|
|
14
|
+
from .render import DEFAULT_TEMPLATE, compose_instructions, render_beliefs
|
|
15
|
+
from .tools import build_forget_tool, build_remember_tool
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"DEFAULT_TEMPLATE",
|
|
19
|
+
"MemoryBinding",
|
|
20
|
+
"PredicateSpec",
|
|
21
|
+
"RecallAgent",
|
|
22
|
+
"RecallMemory",
|
|
23
|
+
"SubjectMemory",
|
|
24
|
+
"VOICE_REGISTRY",
|
|
25
|
+
"attach",
|
|
26
|
+
"build_forget_tool",
|
|
27
|
+
"build_remember_tool",
|
|
28
|
+
"compose_instructions",
|
|
29
|
+
"render_beliefs",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
from importlib.metadata import version as _version
|
|
34
|
+
|
|
35
|
+
__version__ = _version("recall-livekit")
|
|
36
|
+
except Exception: # pragma: no cover - source checkout without metadata
|
|
37
|
+
__version__ = "0.1.0"
|
|
38
|
+
|
|
39
|
+
#: Path of the starter predicate registry for phone and voice callers. Pass it
|
|
40
|
+
#: as ``predicates=`` to :meth:`RecallMemory.open` or set ``POLIGN_PREDICATES``.
|
|
41
|
+
VOICE_REGISTRY = str(resources.files(__name__).joinpath("registry_voice.json"))
|
recall_livekit/agent.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""An Agent that remembers the caller."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from livekit.agents import llm
|
|
9
|
+
from livekit.agents.voice import Agent
|
|
10
|
+
|
|
11
|
+
from .hooks import MemoryBinding
|
|
12
|
+
from .memory import SubjectMemory
|
|
13
|
+
from .render import DEFAULT_TEMPLATE
|
|
14
|
+
from .tools import build_forget_tool, build_remember_tool
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RecallAgent(Agent):
|
|
18
|
+
"""A LiveKit Agent whose instructions carry the caller's remembered facts.
|
|
19
|
+
|
|
20
|
+
On ``on_enter`` it loads every current belief for the subject and appends
|
|
21
|
+
them to the instructions, before the first reply. The ``remember`` tool
|
|
22
|
+
writes new facts and reloads the block. When a caller has more beliefs
|
|
23
|
+
than ``memory.limit``, each user turn also runs a search and adds the
|
|
24
|
+
matching facts to that turn.
|
|
25
|
+
|
|
26
|
+
Subclasses that override ``on_enter`` must ``await super().on_enter()``
|
|
27
|
+
first, before generating a greeting. LiveKit runs ``on_enter`` as a task
|
|
28
|
+
after ``session.start`` returns; ``wait_for_memory`` awaits its first load.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
*,
|
|
34
|
+
memory: SubjectMemory,
|
|
35
|
+
instructions: str,
|
|
36
|
+
context_template: str = DEFAULT_TEMPLATE,
|
|
37
|
+
who: str = "the caller",
|
|
38
|
+
remember_tool: bool = True,
|
|
39
|
+
forget_tool: bool = False,
|
|
40
|
+
search_when_overflowed: bool = True,
|
|
41
|
+
tools: list[llm.Tool | llm.Toolset] | None = None,
|
|
42
|
+
**kwargs: Any,
|
|
43
|
+
) -> None:
|
|
44
|
+
if not isinstance(instructions, str):
|
|
45
|
+
raise TypeError("RecallAgent needs plain string instructions")
|
|
46
|
+
self._binding = MemoryBinding(
|
|
47
|
+
self,
|
|
48
|
+
memory,
|
|
49
|
+
base_instructions=instructions,
|
|
50
|
+
context_template=context_template,
|
|
51
|
+
who=who,
|
|
52
|
+
remember_tool=remember_tool,
|
|
53
|
+
)
|
|
54
|
+
self._search_when_overflowed = search_when_overflowed
|
|
55
|
+
self._memory_loaded = asyncio.Event()
|
|
56
|
+
all_tools: list[llm.Tool | llm.Toolset] = list(tools or [])
|
|
57
|
+
if remember_tool:
|
|
58
|
+
all_tools.append(build_remember_tool(memory, on_change=self.refresh_memory))
|
|
59
|
+
if forget_tool:
|
|
60
|
+
all_tools.append(build_forget_tool(memory, on_change=self.refresh_memory))
|
|
61
|
+
super().__init__(instructions=instructions, tools=all_tools, **kwargs)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def memory(self) -> SubjectMemory:
|
|
65
|
+
return self._binding.memory
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def base_instructions(self) -> str:
|
|
69
|
+
"""The instructions without the memory block."""
|
|
70
|
+
return self._binding.base_instructions
|
|
71
|
+
|
|
72
|
+
async def refresh_memory(self) -> None:
|
|
73
|
+
"""Reload the caller's beliefs and rewrite the instructions."""
|
|
74
|
+
await self._binding.refresh()
|
|
75
|
+
|
|
76
|
+
async def on_enter(self) -> None:
|
|
77
|
+
try:
|
|
78
|
+
await self.refresh_memory()
|
|
79
|
+
finally:
|
|
80
|
+
self._memory_loaded.set()
|
|
81
|
+
|
|
82
|
+
async def wait_for_memory(self) -> None:
|
|
83
|
+
"""Wait until ``on_enter`` has loaded the caller's beliefs. LiveKit runs
|
|
84
|
+
``on_enter`` as a task after ``session.start`` returns, so tests and
|
|
85
|
+
code that inspects the instructions right after start should await this."""
|
|
86
|
+
await self._memory_loaded.wait()
|
|
87
|
+
|
|
88
|
+
async def on_user_turn_completed(
|
|
89
|
+
self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage
|
|
90
|
+
) -> None:
|
|
91
|
+
if not self._search_when_overflowed or not self.memory.overflowed:
|
|
92
|
+
return
|
|
93
|
+
text = new_message.text_content
|
|
94
|
+
if not text:
|
|
95
|
+
return
|
|
96
|
+
hits = await self.memory.search(text)
|
|
97
|
+
# Facts already in the instructions add nothing to the turn.
|
|
98
|
+
shown = {(b.predicate, str(b.value)) for b in self.memory.beliefs}
|
|
99
|
+
extra = [b for b in hits if (b.predicate, str(b.value)) not in shown]
|
|
100
|
+
if extra:
|
|
101
|
+
turn_ctx.add_message(role="system", content=self._binding.turn_context(extra))
|
recall_livekit/hooks.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Attach Recall memory to an Agent subclass you already have."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from livekit.agents import llm
|
|
6
|
+
from livekit.agents.voice import Agent
|
|
7
|
+
|
|
8
|
+
from .memory import SubjectMemory
|
|
9
|
+
from .render import DEFAULT_TEMPLATE, compose_instructions, render_beliefs
|
|
10
|
+
from .tools import build_forget_tool, build_remember_tool
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MemoryBinding:
|
|
14
|
+
"""Keeps an agent's instructions in step with one caller's beliefs."""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
agent: Agent,
|
|
19
|
+
memory: SubjectMemory,
|
|
20
|
+
*,
|
|
21
|
+
base_instructions: str,
|
|
22
|
+
context_template: str = DEFAULT_TEMPLATE,
|
|
23
|
+
who: str = "the caller",
|
|
24
|
+
remember_tool: bool = True,
|
|
25
|
+
) -> None:
|
|
26
|
+
self.agent = agent
|
|
27
|
+
self.memory = memory
|
|
28
|
+
self.base_instructions = base_instructions
|
|
29
|
+
self.context_template = context_template
|
|
30
|
+
self.who = who
|
|
31
|
+
self.remember_tool = remember_tool
|
|
32
|
+
|
|
33
|
+
def render(self) -> str:
|
|
34
|
+
return render_beliefs(
|
|
35
|
+
self.memory.beliefs,
|
|
36
|
+
registry=self.memory.registry,
|
|
37
|
+
template=self.context_template,
|
|
38
|
+
who=self.who,
|
|
39
|
+
remember_tool=self.remember_tool,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
async def refresh(self) -> None:
|
|
43
|
+
"""Reload the caller's beliefs and rewrite the agent's instructions."""
|
|
44
|
+
await self.memory.load()
|
|
45
|
+
await self.agent.update_instructions(compose_instructions(self.base_instructions, self.render()))
|
|
46
|
+
|
|
47
|
+
def turn_context(self, hits: list) -> str:
|
|
48
|
+
"""The block added to a turn when a per-turn search found more facts."""
|
|
49
|
+
return render_beliefs(
|
|
50
|
+
hits,
|
|
51
|
+
registry=self.memory.registry,
|
|
52
|
+
template=self.context_template,
|
|
53
|
+
who=self.who,
|
|
54
|
+
remember_tool=False,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def attach(
|
|
59
|
+
agent: Agent,
|
|
60
|
+
memory: SubjectMemory,
|
|
61
|
+
*,
|
|
62
|
+
context_template: str = DEFAULT_TEMPLATE,
|
|
63
|
+
who: str = "the caller",
|
|
64
|
+
remember_tool: bool = True,
|
|
65
|
+
forget_tool: bool = False,
|
|
66
|
+
) -> MemoryBinding:
|
|
67
|
+
"""Give an existing Agent the memory block and the ``remember`` tool.
|
|
68
|
+
|
|
69
|
+
Await it before ``session.start`` or at the top of the agent's ``on_enter``.
|
|
70
|
+
The agent's instructions must be a plain string. Per-turn search for
|
|
71
|
+
callers with more beliefs than fit the block needs ``RecallAgent``.
|
|
72
|
+
"""
|
|
73
|
+
instructions = agent.instructions
|
|
74
|
+
if not isinstance(instructions, str):
|
|
75
|
+
raise TypeError("attach needs plain string instructions; Instructions objects are not supported")
|
|
76
|
+
binding = MemoryBinding(
|
|
77
|
+
agent,
|
|
78
|
+
memory,
|
|
79
|
+
base_instructions=instructions,
|
|
80
|
+
context_template=context_template,
|
|
81
|
+
who=who,
|
|
82
|
+
remember_tool=remember_tool,
|
|
83
|
+
)
|
|
84
|
+
tools: list[llm.Tool | llm.Toolset] = list(agent.tools)
|
|
85
|
+
if remember_tool:
|
|
86
|
+
tools.append(build_remember_tool(memory, on_change=binding.refresh))
|
|
87
|
+
if forget_tool:
|
|
88
|
+
tools.append(build_forget_tool(memory, on_change=binding.refresh))
|
|
89
|
+
await agent.update_tools(tools)
|
|
90
|
+
await binding.refresh()
|
|
91
|
+
return binding
|
recall_livekit/memory.py
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""The shared Recall client and the per-caller view built on it."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import logging
|
|
7
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, TypeVar
|
|
10
|
+
|
|
11
|
+
from polign_recall import Belief, Client, RecallError, RememberResult
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger("recall_livekit")
|
|
14
|
+
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
|
|
17
|
+
_MISSING: Any = object()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _describe(exc: BaseException) -> str:
|
|
21
|
+
text = str(exc)
|
|
22
|
+
return f"{type(exc).__name__}: {text}" if text else type(exc).__name__
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class PredicateSpec:
|
|
27
|
+
"""One entry of the Recall predicate registry."""
|
|
28
|
+
|
|
29
|
+
name: str
|
|
30
|
+
cardinality: str # "single" or "multi"
|
|
31
|
+
value_type: str # "string", "number", or "boolean"
|
|
32
|
+
description: str
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RecallMemory:
|
|
36
|
+
"""One Recall client for a worker process.
|
|
37
|
+
|
|
38
|
+
Create it once in the server's ``setup_fnc`` (LiveKit calls that once per
|
|
39
|
+
process) and keep it in ``JobProcess.userdata``. Every ``polign_recall.Client``
|
|
40
|
+
is a ``polign mcp`` subprocess, so one per turn or per session is wasteful.
|
|
41
|
+
Calls are serialized on that subprocess; the local read path is a few
|
|
42
|
+
milliseconds, so a handful of concurrent sessions per process share it well.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, client: Client) -> None:
|
|
46
|
+
self._client = client
|
|
47
|
+
self._registry: dict[str, PredicateSpec] = {}
|
|
48
|
+
for entry in client.predicates():
|
|
49
|
+
spec = PredicateSpec(
|
|
50
|
+
name=entry["predicate"],
|
|
51
|
+
cardinality=entry.get("cardinality", "single"),
|
|
52
|
+
value_type=entry.get("value_type") or "string",
|
|
53
|
+
description=entry.get("description", ""),
|
|
54
|
+
)
|
|
55
|
+
self._registry[spec.name] = spec
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def open(
|
|
59
|
+
cls,
|
|
60
|
+
*,
|
|
61
|
+
url: str | None = None,
|
|
62
|
+
api_key: str | None = None,
|
|
63
|
+
collection: str | None = None,
|
|
64
|
+
predicates: str | None = None,
|
|
65
|
+
command: Sequence[str] | None = None,
|
|
66
|
+
env: Mapping[str, str] | None = None,
|
|
67
|
+
timeout: float = 30.0,
|
|
68
|
+
write: bool = True,
|
|
69
|
+
) -> RecallMemory:
|
|
70
|
+
"""Start the Recall subprocess and read its predicate registry.
|
|
71
|
+
|
|
72
|
+
``url``, ``api_key``, ``collection`` and ``predicates`` (a registry file
|
|
73
|
+
path) become the ``POLIGN_URL``, ``POLIGN_API_KEY``, ``POLIGN_COLLECTION``
|
|
74
|
+
and ``POLIGN_PREDICATES`` variables of the subprocess; anything left
|
|
75
|
+
unset falls through to the worker's environment. ``command`` replaces
|
|
76
|
+
the default ``polign mcp -memory-only -write`` argv, for a binary that
|
|
77
|
+
is not on ``PATH``.
|
|
78
|
+
"""
|
|
79
|
+
merged = dict(env or {})
|
|
80
|
+
for key, value in (
|
|
81
|
+
("POLIGN_URL", url),
|
|
82
|
+
("POLIGN_API_KEY", api_key),
|
|
83
|
+
("POLIGN_COLLECTION", collection),
|
|
84
|
+
("POLIGN_PREDICATES", predicates),
|
|
85
|
+
):
|
|
86
|
+
if value is not None:
|
|
87
|
+
merged[key] = value
|
|
88
|
+
client = Client(command=command, env=merged, timeout=timeout, write=write)
|
|
89
|
+
try:
|
|
90
|
+
return cls(client)
|
|
91
|
+
except BaseException:
|
|
92
|
+
client.close()
|
|
93
|
+
raise
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def client(self) -> Client:
|
|
97
|
+
return self._client
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def registry(self) -> Mapping[str, PredicateSpec]:
|
|
101
|
+
"""The closed set of predicates this Recall instance accepts."""
|
|
102
|
+
return self._registry
|
|
103
|
+
|
|
104
|
+
def for_subject(
|
|
105
|
+
self,
|
|
106
|
+
subject: str,
|
|
107
|
+
*,
|
|
108
|
+
limit: int = 20,
|
|
109
|
+
read_timeout: float = 0.5,
|
|
110
|
+
write_timeout: float = 5.0,
|
|
111
|
+
) -> SubjectMemory:
|
|
112
|
+
"""A view of one caller's memory. ``subject`` should be a stable, auth-derived
|
|
113
|
+
identifier such as the participant identity, never the room name."""
|
|
114
|
+
if not subject or not subject.strip():
|
|
115
|
+
raise ValueError("subject must be a non-empty string")
|
|
116
|
+
return SubjectMemory(
|
|
117
|
+
self, subject, limit=limit, read_timeout=read_timeout, write_timeout=write_timeout
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def close(self) -> None:
|
|
121
|
+
self._client.close()
|
|
122
|
+
|
|
123
|
+
def __enter__(self) -> RecallMemory:
|
|
124
|
+
return self
|
|
125
|
+
|
|
126
|
+
def __exit__(self, *exc: object) -> None:
|
|
127
|
+
self.close()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class SubjectMemory:
|
|
131
|
+
"""One caller's beliefs, with the async helpers the agent hooks need.
|
|
132
|
+
|
|
133
|
+
Reads fail open: a slow or unavailable Recall returns the last loaded
|
|
134
|
+
beliefs (or none) and logs a warning, so the voice session keeps going.
|
|
135
|
+
Writes raise, so the tool can tell the model the fact was not saved.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
def __init__(
|
|
139
|
+
self,
|
|
140
|
+
memory: RecallMemory,
|
|
141
|
+
subject: str,
|
|
142
|
+
*,
|
|
143
|
+
limit: int,
|
|
144
|
+
read_timeout: float,
|
|
145
|
+
write_timeout: float,
|
|
146
|
+
) -> None:
|
|
147
|
+
if limit < 1:
|
|
148
|
+
raise ValueError("limit must be at least 1")
|
|
149
|
+
self._memory = memory
|
|
150
|
+
self.subject = subject
|
|
151
|
+
self.limit = limit
|
|
152
|
+
self.read_timeout = read_timeout
|
|
153
|
+
self.write_timeout = write_timeout
|
|
154
|
+
self.beliefs: list[Belief] = []
|
|
155
|
+
self.loaded = False
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def registry(self) -> Mapping[str, PredicateSpec]:
|
|
159
|
+
return self._memory.registry
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def overflowed(self) -> bool:
|
|
163
|
+
"""True when the last load hit the cap, so beliefs may be missing from
|
|
164
|
+
the prompt and a per-turn search is worth running."""
|
|
165
|
+
return len(self.beliefs) >= self.limit
|
|
166
|
+
|
|
167
|
+
async def load(self) -> list[Belief]:
|
|
168
|
+
"""Every current belief about the subject, up to ``limit``."""
|
|
169
|
+
client = self._memory.client
|
|
170
|
+
try:
|
|
171
|
+
beliefs = await self._call(
|
|
172
|
+
lambda: client.recall(subject=self.subject, limit=self.limit), self.read_timeout
|
|
173
|
+
)
|
|
174
|
+
except (RecallError, asyncio.TimeoutError) as exc:
|
|
175
|
+
logger.warning("recall load failed for subject %r: %s", self.subject, _describe(exc))
|
|
176
|
+
return self.beliefs
|
|
177
|
+
self.beliefs = list(beliefs)
|
|
178
|
+
self.loaded = True
|
|
179
|
+
return self.beliefs
|
|
180
|
+
|
|
181
|
+
async def search(self, query: str, *, k: int = 5) -> list[Belief]:
|
|
182
|
+
"""Beliefs about the subject that match ``query``. Uses the embedder the
|
|
183
|
+
Recall subprocess was started with; the default is word overlap."""
|
|
184
|
+
client = self._memory.client
|
|
185
|
+
try:
|
|
186
|
+
hits = await self._call(
|
|
187
|
+
lambda: client.recall(subject=self.subject, query=query, limit=k),
|
|
188
|
+
self.read_timeout,
|
|
189
|
+
)
|
|
190
|
+
except (RecallError, asyncio.TimeoutError) as exc:
|
|
191
|
+
logger.warning("recall search failed for subject %r: %s", self.subject, _describe(exc))
|
|
192
|
+
return []
|
|
193
|
+
return list(hits)
|
|
194
|
+
|
|
195
|
+
async def remember(self, predicate: str, value: Any, *, source: str | None = None) -> RememberResult:
|
|
196
|
+
client = self._memory.client
|
|
197
|
+
result = await self._call(
|
|
198
|
+
lambda: client.remember(self.subject, predicate, value, source=source),
|
|
199
|
+
self.write_timeout,
|
|
200
|
+
)
|
|
201
|
+
if not isinstance(result, RememberResult): # pragma: no cover - typed path only
|
|
202
|
+
raise RecallError("unexpected extraction result from a typed remember")
|
|
203
|
+
return result
|
|
204
|
+
|
|
205
|
+
async def forget(self, predicate: str, value: Any = _MISSING, *, all: bool = False) -> int:
|
|
206
|
+
client = self._memory.client
|
|
207
|
+
if value is _MISSING:
|
|
208
|
+
return await self._call(
|
|
209
|
+
lambda: client.forget(self.subject, predicate, all=all), self.write_timeout
|
|
210
|
+
)
|
|
211
|
+
return await self._call(
|
|
212
|
+
lambda: client.forget(self.subject, predicate, value), self.write_timeout
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def coerce(self, predicate: str, value: Any) -> Any:
|
|
216
|
+
"""Turn a model-supplied value into the registry's type for ``predicate``."""
|
|
217
|
+
spec = self.registry.get(predicate)
|
|
218
|
+
if spec is None:
|
|
219
|
+
raise ValueError(f"unknown memory type {predicate!r}")
|
|
220
|
+
if spec.value_type == "number":
|
|
221
|
+
if isinstance(value, bool):
|
|
222
|
+
raise ValueError(f"{predicate} takes a number")
|
|
223
|
+
if isinstance(value, (int, float)):
|
|
224
|
+
return value
|
|
225
|
+
text = str(value).strip().replace(",", "")
|
|
226
|
+
try:
|
|
227
|
+
number = float(text)
|
|
228
|
+
except ValueError as exc:
|
|
229
|
+
raise ValueError(f"{predicate} takes a number, got {value!r}") from exc
|
|
230
|
+
return int(number) if number.is_integer() else number
|
|
231
|
+
if spec.value_type == "boolean":
|
|
232
|
+
if isinstance(value, bool):
|
|
233
|
+
return value
|
|
234
|
+
text = str(value).strip().lower()
|
|
235
|
+
if text in ("true", "yes", "y", "1", "on"):
|
|
236
|
+
return True
|
|
237
|
+
if text in ("false", "no", "n", "0", "off"):
|
|
238
|
+
return False
|
|
239
|
+
raise ValueError(f"{predicate} takes yes or no, got {value!r}")
|
|
240
|
+
text = str(value).strip()
|
|
241
|
+
if not text:
|
|
242
|
+
raise ValueError(f"{predicate} needs a value")
|
|
243
|
+
return text
|
|
244
|
+
|
|
245
|
+
async def _call(self, fn: Callable[[], T], timeout: float) -> T:
|
|
246
|
+
# The Recall client is blocking; a thread keeps the audio pipeline
|
|
247
|
+
# responsive. On timeout the thread finishes on its own later.
|
|
248
|
+
return await asyncio.wait_for(asyncio.to_thread(fn), timeout)
|
recall_livekit/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": {
|
|
3
|
+
"cardinality": "single",
|
|
4
|
+
"value_type": "string",
|
|
5
|
+
"description": "The name the caller asks to be called"
|
|
6
|
+
},
|
|
7
|
+
"preferred_language": {
|
|
8
|
+
"cardinality": "single",
|
|
9
|
+
"value_type": "string",
|
|
10
|
+
"description": "The language the caller wants to speak"
|
|
11
|
+
},
|
|
12
|
+
"callback_number": {
|
|
13
|
+
"cardinality": "single",
|
|
14
|
+
"value_type": "string",
|
|
15
|
+
"description": "The phone number the caller wants to be called back on"
|
|
16
|
+
},
|
|
17
|
+
"email": {
|
|
18
|
+
"cardinality": "single",
|
|
19
|
+
"value_type": "string",
|
|
20
|
+
"description": "The email address the caller wants written follow-ups sent to"
|
|
21
|
+
},
|
|
22
|
+
"timezone": {
|
|
23
|
+
"cardinality": "single",
|
|
24
|
+
"value_type": "string",
|
|
25
|
+
"description": "The caller's timezone or city, for scheduling"
|
|
26
|
+
},
|
|
27
|
+
"account_tier": {
|
|
28
|
+
"cardinality": "single",
|
|
29
|
+
"value_type": "string",
|
|
30
|
+
"description": "The plan or membership level the caller is on"
|
|
31
|
+
},
|
|
32
|
+
"consents_to_recording": {
|
|
33
|
+
"cardinality": "single",
|
|
34
|
+
"value_type": "boolean",
|
|
35
|
+
"description": "Whether the caller agreed to have calls recorded"
|
|
36
|
+
},
|
|
37
|
+
"prefers_response_style": {
|
|
38
|
+
"cardinality": "single",
|
|
39
|
+
"value_type": "string",
|
|
40
|
+
"description": "How the caller likes answers, such as brief or step by step"
|
|
41
|
+
},
|
|
42
|
+
"open_issue": {
|
|
43
|
+
"cardinality": "multi",
|
|
44
|
+
"value_type": "string",
|
|
45
|
+
"description": "A problem the caller reported that is not resolved yet"
|
|
46
|
+
},
|
|
47
|
+
"owns_product": {
|
|
48
|
+
"cardinality": "multi",
|
|
49
|
+
"value_type": "string",
|
|
50
|
+
"description": "A product or service the caller owns or subscribes to"
|
|
51
|
+
},
|
|
52
|
+
"uses_technology": {
|
|
53
|
+
"cardinality": "multi",
|
|
54
|
+
"value_type": "string",
|
|
55
|
+
"description": "A device, platform, or tool the caller uses"
|
|
56
|
+
}
|
|
57
|
+
}
|
recall_livekit/render.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Turn beliefs into the block of text the model reads."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable, Mapping
|
|
6
|
+
|
|
7
|
+
from polign_recall import Belief
|
|
8
|
+
|
|
9
|
+
from .memory import PredicateSpec
|
|
10
|
+
|
|
11
|
+
DEFAULT_TEMPLATE = "<recall_memory>\n{context}\n</recall_memory>"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _observed(belief: Belief) -> str:
|
|
15
|
+
observed = getattr(belief, "observed_at", "") or ""
|
|
16
|
+
return observed[:10]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def render_beliefs(
|
|
20
|
+
beliefs: Iterable[Belief],
|
|
21
|
+
*,
|
|
22
|
+
registry: Mapping[str, PredicateSpec] | None = None,
|
|
23
|
+
template: str = DEFAULT_TEMPLATE,
|
|
24
|
+
who: str = "the caller",
|
|
25
|
+
remember_tool: bool = True,
|
|
26
|
+
) -> str:
|
|
27
|
+
"""Render current beliefs as a memory block.
|
|
28
|
+
|
|
29
|
+
Single-valued predicates print one line each; multi-valued ones are
|
|
30
|
+
grouped on one line. ``template`` must contain a literal ``{context}``.
|
|
31
|
+
"""
|
|
32
|
+
if "{context}" not in template:
|
|
33
|
+
raise ValueError("context template must contain a literal {context} placeholder")
|
|
34
|
+
|
|
35
|
+
grouped: dict[str, list[Belief]] = {}
|
|
36
|
+
for belief in beliefs:
|
|
37
|
+
grouped.setdefault(belief.predicate, []).append(belief)
|
|
38
|
+
|
|
39
|
+
lines: list[str] = []
|
|
40
|
+
if grouped:
|
|
41
|
+
lines.append(
|
|
42
|
+
f"Facts remembered about {who} from earlier conversations. "
|
|
43
|
+
f"Treat them as true unless {who} says otherwise, and use them naturally "
|
|
44
|
+
"without reading the list aloud."
|
|
45
|
+
)
|
|
46
|
+
for predicate, items in grouped.items():
|
|
47
|
+
spec = registry.get(predicate) if registry else None
|
|
48
|
+
multi = spec is not None and spec.cardinality == "multi"
|
|
49
|
+
if multi or len(items) > 1:
|
|
50
|
+
values = "; ".join(str(b.value) for b in items)
|
|
51
|
+
lines.append(f"- {predicate}: {values}")
|
|
52
|
+
else:
|
|
53
|
+
belief = items[0]
|
|
54
|
+
when = _observed(belief)
|
|
55
|
+
suffix = f" (observed {when})" if when else ""
|
|
56
|
+
lines.append(f"- {predicate}: {belief.value}{suffix}")
|
|
57
|
+
else:
|
|
58
|
+
lines.append(f"Nothing is remembered about {who} yet.")
|
|
59
|
+
|
|
60
|
+
if remember_tool:
|
|
61
|
+
kinds = ", ".join(registry.keys()) if registry else "the registered memory types"
|
|
62
|
+
lines.append(
|
|
63
|
+
f"When {who} states a lasting fact of one of these kinds, call the remember tool "
|
|
64
|
+
f"with it: {kinds}. Corrections go through the same tool. "
|
|
65
|
+
"Do not mention the memory system unless asked."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return template.replace("{context}", "\n".join(lines))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def compose_instructions(base: str, memory_block: str) -> str:
|
|
72
|
+
"""The agent's instructions with the memory block appended."""
|
|
73
|
+
base = base.rstrip()
|
|
74
|
+
return f"{base}\n\n{memory_block}" if base else memory_block
|
recall_livekit/tools.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Function tools that let the voice model write memory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Awaitable, Callable
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from livekit.agents import llm
|
|
10
|
+
from polign_recall import RecallError
|
|
11
|
+
|
|
12
|
+
from .memory import SubjectMemory
|
|
13
|
+
|
|
14
|
+
OnChange = Callable[[], Awaitable[None]] | None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _predicate_property(memory: SubjectMemory) -> dict[str, Any]:
|
|
18
|
+
names = list(memory.registry)
|
|
19
|
+
described = "; ".join(
|
|
20
|
+
f"{spec.name}: {spec.description or spec.name}"
|
|
21
|
+
+ (" (can hold several values)" if spec.cardinality == "multi" else "")
|
|
22
|
+
for spec in memory.registry.values()
|
|
23
|
+
)
|
|
24
|
+
return {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"enum": names,
|
|
27
|
+
"description": f"The kind of fact. One of: {described}.",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def build_remember_tool(memory: SubjectMemory, *, on_change: OnChange = None) -> llm.RawFunctionTool:
|
|
32
|
+
"""A ``remember`` tool whose predicate list is the Recall registry.
|
|
33
|
+
|
|
34
|
+
``on_change`` runs after a successful write, so the agent can reload its
|
|
35
|
+
memory block before the next turn.
|
|
36
|
+
"""
|
|
37
|
+
schema = {
|
|
38
|
+
"name": "remember",
|
|
39
|
+
"description": (
|
|
40
|
+
"Save a lasting fact the caller stated about themselves, such as their name, "
|
|
41
|
+
"a preference, or an open issue. Call it once per fact, as soon as the fact is "
|
|
42
|
+
"clear. Storing a new value for a single-valued kind replaces the old one."
|
|
43
|
+
),
|
|
44
|
+
"parameters": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"properties": {
|
|
47
|
+
"predicate": _predicate_property(memory),
|
|
48
|
+
"value": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"description": "The fact itself, short and in the caller's words. "
|
|
51
|
+
"Numbers as digits, yes/no facts as true or false.",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
"required": ["predicate", "value"],
|
|
55
|
+
"additionalProperties": False,
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async def remember(raw_arguments: dict[str, object]) -> str:
|
|
60
|
+
predicate = str(raw_arguments.get("predicate", "")).strip()
|
|
61
|
+
if predicate not in memory.registry:
|
|
62
|
+
raise llm.ToolError(
|
|
63
|
+
f"Unknown memory kind {predicate!r}. Use one of: {', '.join(memory.registry)}."
|
|
64
|
+
)
|
|
65
|
+
try:
|
|
66
|
+
value = memory.coerce(predicate, raw_arguments.get("value"))
|
|
67
|
+
except ValueError as exc:
|
|
68
|
+
raise llm.ToolError(str(exc)) from exc
|
|
69
|
+
try:
|
|
70
|
+
result = await memory.remember(predicate, value)
|
|
71
|
+
except RecallError as exc:
|
|
72
|
+
raise llm.ToolError(f"The fact was not saved: {exc}") from exc
|
|
73
|
+
except asyncio.TimeoutError as exc:
|
|
74
|
+
raise llm.ToolError("Memory is slow right now; the fact was not saved.") from exc
|
|
75
|
+
if on_change is not None:
|
|
76
|
+
await on_change()
|
|
77
|
+
if result.already_known:
|
|
78
|
+
return f"Already remembered: {predicate} is {value}."
|
|
79
|
+
if result.superseded:
|
|
80
|
+
old = ", ".join(str(b.value) for b in result.superseded)
|
|
81
|
+
return f"Updated {predicate} to {value}; it was {old}."
|
|
82
|
+
return f"Remembered {predicate}: {value}."
|
|
83
|
+
|
|
84
|
+
return llm.function_tool(remember, raw_schema=schema)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def build_forget_tool(memory: SubjectMemory, *, on_change: OnChange = None) -> llm.RawFunctionTool:
|
|
88
|
+
"""A ``forget`` tool. Off by default in ``RecallAgent``; enable it when the
|
|
89
|
+
caller should be able to withdraw a fact by asking."""
|
|
90
|
+
schema = {
|
|
91
|
+
"name": "forget",
|
|
92
|
+
"description": (
|
|
93
|
+
"Withdraw a remembered fact when the caller asks you to forget it. "
|
|
94
|
+
"Give the exact value to withdraw, or set everything to true to withdraw every "
|
|
95
|
+
"value of that kind. The record of the change is kept."
|
|
96
|
+
),
|
|
97
|
+
"parameters": {
|
|
98
|
+
"type": "object",
|
|
99
|
+
"properties": {
|
|
100
|
+
"predicate": _predicate_property(memory),
|
|
101
|
+
"value": {"type": "string", "description": "The value to withdraw."},
|
|
102
|
+
"everything": {
|
|
103
|
+
"type": "boolean",
|
|
104
|
+
"description": "Withdraw every value of this kind instead of one.",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
"required": ["predicate"],
|
|
108
|
+
"additionalProperties": False,
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async def forget(raw_arguments: dict[str, object]) -> str:
|
|
113
|
+
predicate = str(raw_arguments.get("predicate", "")).strip()
|
|
114
|
+
if predicate not in memory.registry:
|
|
115
|
+
raise llm.ToolError(
|
|
116
|
+
f"Unknown memory kind {predicate!r}. Use one of: {', '.join(memory.registry)}."
|
|
117
|
+
)
|
|
118
|
+
everything = bool(raw_arguments.get("everything", False))
|
|
119
|
+
raw_value = raw_arguments.get("value")
|
|
120
|
+
if not everything and (raw_value is None or str(raw_value).strip() == ""):
|
|
121
|
+
raise llm.ToolError("Give the value to withdraw, or set everything to true.")
|
|
122
|
+
try:
|
|
123
|
+
if everything:
|
|
124
|
+
count = await memory.forget(predicate, all=True)
|
|
125
|
+
else:
|
|
126
|
+
count = await memory.forget(predicate, memory.coerce(predicate, raw_value))
|
|
127
|
+
except ValueError as exc:
|
|
128
|
+
raise llm.ToolError(str(exc)) from exc
|
|
129
|
+
except RecallError as exc:
|
|
130
|
+
raise llm.ToolError(f"Nothing was withdrawn: {exc}") from exc
|
|
131
|
+
except asyncio.TimeoutError as exc:
|
|
132
|
+
raise llm.ToolError("Memory is slow right now; nothing was withdrawn.") from exc
|
|
133
|
+
if on_change is not None:
|
|
134
|
+
await on_change()
|
|
135
|
+
if count == 0:
|
|
136
|
+
return f"There was no remembered {predicate} to withdraw."
|
|
137
|
+
return f"Withdrew {count} remembered value(s) of {predicate}."
|
|
138
|
+
|
|
139
|
+
return llm.function_tool(forget, raw_schema=schema)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: recall-livekit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed, correctable long-term memory for LiveKit voice agents, backed by Recall by Polign
|
|
5
|
+
Project-URL: Homepage, https://polign.com
|
|
6
|
+
Project-URL: Documentation, https://polign.com/integrations.html
|
|
7
|
+
Project-URL: Repository, https://github.com/Polign/polign
|
|
8
|
+
Project-URL: Issues, https://github.com/Polign/polign/issues
|
|
9
|
+
Author: Polign
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent memory,livekit,polign,recall,voice agent
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: livekit-agents<2,>=1.8
|
|
21
|
+
Requires-Dist: polign-recall>=0.2.0
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# recall-livekit
|
|
25
|
+
|
|
26
|
+
Long-term memory for [LiveKit Agents](https://github.com/livekit/agents) voice
|
|
27
|
+
agents, backed by [Recall by Polign](https://polign.com/recall.html).
|
|
28
|
+
|
|
29
|
+
The agent loads everything it knows about the caller before the first reply,
|
|
30
|
+
and the model saves new facts through a `remember` tool. Facts are typed:
|
|
31
|
+
each one is a predicate from a closed registry with a value, so "call me Sam"
|
|
32
|
+
replaces the old name instead of piling up a second one, and the history of
|
|
33
|
+
the change is kept. No second model runs on the read path, and no embedding
|
|
34
|
+
service is needed.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install recall-livekit "livekit-agents[openai,deepgram,cartesia,silero]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Recall runs as a `polign mcp` subprocess, so the `polign` CLI has to be on the
|
|
41
|
+
worker's `PATH` (or passed as `command=`), and it needs a polign_db server to
|
|
42
|
+
store into. [Get started](https://polign.com/developers.html) covers both.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from livekit.agents import AgentServer, AgentSession, JobContext, JobProcess, cli
|
|
48
|
+
from livekit.plugins import cartesia, deepgram, openai, silero
|
|
49
|
+
from recall_livekit import VOICE_REGISTRY, RecallAgent, RecallMemory
|
|
50
|
+
|
|
51
|
+
server = AgentServer()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def setup(proc: JobProcess) -> None:
|
|
55
|
+
# one Recall subprocess per worker process
|
|
56
|
+
proc.userdata["recall"] = RecallMemory.open(
|
|
57
|
+
url="http://memory.internal:23000", # or POLIGN_URL in the environment
|
|
58
|
+
predicates=VOICE_REGISTRY, # or your own registry file
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
server.setup_fnc = setup
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@server.rtc_session()
|
|
66
|
+
async def entrypoint(ctx: JobContext) -> None:
|
|
67
|
+
participant = await ctx.wait_for_participant()
|
|
68
|
+
memory = ctx.proc.userdata["recall"].for_subject(participant.identity)
|
|
69
|
+
|
|
70
|
+
session = AgentSession(
|
|
71
|
+
stt=deepgram.STT(), llm=openai.LLM(model="gpt-4.1-mini"),
|
|
72
|
+
tts=cartesia.TTS(), vad=silero.VAD.load(),
|
|
73
|
+
)
|
|
74
|
+
await session.start(
|
|
75
|
+
agent=RecallAgent(
|
|
76
|
+
memory=memory,
|
|
77
|
+
instructions="You are the support line for Acme. Use what you remember about the caller.",
|
|
78
|
+
),
|
|
79
|
+
room=ctx.room,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
cli.run_app(server)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
What happens on a call:
|
|
88
|
+
|
|
89
|
+
1. `on_enter` loads the caller's current beliefs and appends them to the
|
|
90
|
+
instructions inside a `<recall_memory>` block, before the greeting.
|
|
91
|
+
2. The caller says "actually call me Sam, and I moved to Denver". The model
|
|
92
|
+
calls `remember` twice. Recall supersedes the old name and timezone, and
|
|
93
|
+
the agent rewrites its instructions so the next sentence already uses Sam.
|
|
94
|
+
3. A week later the same identity calls back and step 1 finds the facts.
|
|
95
|
+
|
|
96
|
+
Nothing is searched per turn. A caller's typed facts are a short list, so the
|
|
97
|
+
whole set fits in the prompt. When a caller has more beliefs than `limit`
|
|
98
|
+
(default 20), each user turn also runs a search and adds matching facts to
|
|
99
|
+
that turn only.
|
|
100
|
+
|
|
101
|
+
## Your own Agent subclass
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from recall_livekit import attach
|
|
105
|
+
|
|
106
|
+
agent = FrontDesk() # any Agent with string instructions
|
|
107
|
+
await attach(agent, memory, who="the guest")
|
|
108
|
+
await session.start(agent, room=ctx.room)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`attach` adds the memory block and the `remember` tool. It does not do the
|
|
112
|
+
per-turn search for overflowing callers; use `RecallAgent` for that.
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
| Where | Option | Default | What it does |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| `RecallMemory.open` | `url`, `api_key`, `collection`, `predicates` | worker environment | Connection for the subprocess (`POLIGN_URL`, `POLIGN_API_KEY`, `POLIGN_COLLECTION`, `POLIGN_PREDICATES`) |
|
|
119
|
+
| `RecallMemory.open` | `command` | `polign mcp -memory-only -write` | The subprocess argv, for a binary that is not on `PATH` |
|
|
120
|
+
| `for_subject` | `limit` | 20 | Beliefs loaded into the prompt; above it, per-turn search kicks in |
|
|
121
|
+
| `for_subject` | `read_timeout`, `write_timeout` | 0.5 s, 5 s | Reads fail open (last known beliefs); writes tell the model the fact was not saved |
|
|
122
|
+
| `RecallAgent` | `context_template` | `<recall_memory>\n{context}\n</recall_memory>` | Wrapper around the block; must contain `{context}` |
|
|
123
|
+
| `RecallAgent` | `who` | `"the caller"` | How the block refers to the person |
|
|
124
|
+
| `RecallAgent` | `remember_tool`, `forget_tool` | on, off | Which tools the model gets |
|
|
125
|
+
| `RecallAgent` | `search_when_overflowed` | on | Per-turn search when the caller has more beliefs than `limit` |
|
|
126
|
+
|
|
127
|
+
## Custom predicates
|
|
128
|
+
|
|
129
|
+
Predicates are a JSON file. The `remember` tool's schema is built from it, so
|
|
130
|
+
the model only ever sees the names you allow.
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"name": { "cardinality": "single", "value_type": "string", "description": "The name the caller asks to be called" },
|
|
135
|
+
"open_issue": { "cardinality": "multi", "value_type": "string", "description": "A problem the caller reported that is not resolved yet" }
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`single` means a newer value replaces the old one; `multi` means each value
|
|
140
|
+
is an additional fact. `value_type` is `string`, `number`, or `boolean`. The
|
|
141
|
+
file replaces Recall's built-in registry entirely. `VOICE_REGISTRY` is a
|
|
142
|
+
starter set for callers: name, preferred language, callback number, email,
|
|
143
|
+
timezone, account tier, recording consent, response style, open issues,
|
|
144
|
+
owned products, and technologies used.
|
|
145
|
+
|
|
146
|
+
## Subjects and retention
|
|
147
|
+
|
|
148
|
+
Use a stable, auth-derived identifier as the subject, such as the participant
|
|
149
|
+
identity your token server issued. Never the room name. Recall keeps the
|
|
150
|
+
record of every change while the current view updates; enable `forget_tool`
|
|
151
|
+
if callers should be able to withdraw a fact by asking, and see the Recall
|
|
152
|
+
docs for retention and export.
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
`polign-recall` is not on PyPI yet, so install it from source first:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
python -m pip install "polign-recall @ git+https://github.com/Polign/recall@python-v0.2.0#subdirectory=python"
|
|
160
|
+
cd python/recall-livekit
|
|
161
|
+
python -m pip install -e . pytest pytest-asyncio
|
|
162
|
+
pytest tests/unit_tests -q # fake Recall subprocess, scripted model
|
|
163
|
+
pytest tests/integration_tests -v # real polign-server and polign CLI
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The integration tests locate the binaries like the SDK's tests do
|
|
167
|
+
(`POLIGN_SERVER`, `POLIGN_SOURCE`, `POLIGN_SERVER_VERSION`, or the latest
|
|
168
|
+
release download) and skip when none is found.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
recall_livekit/__init__.py,sha256=C7xszlpLhHBqM6QHskx0VaB9lIy7mZndC86CcyEYVk0,1371
|
|
2
|
+
recall_livekit/agent.py,sha256=kJYLelOVYpneM6eVxAJ0aYM4KJkaRYe7plDf5NpT4DQ,3832
|
|
3
|
+
recall_livekit/hooks.py,sha256=t0MpDriHo9MKhvFtFn1-seCrXpAO_zn1kPVlTRXUKc8,3043
|
|
4
|
+
recall_livekit/memory.py,sha256=NoOLpfia_Vg7jyNXVZjGdFlH2J-7sjkLwDwdBzIbW0s,9195
|
|
5
|
+
recall_livekit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
recall_livekit/registry_voice.json,sha256=MlzMq5mL8cls4l1FVnMw2hr9BkD2CAZucc0MlA2kaR0,1692
|
|
7
|
+
recall_livekit/render.py,sha256=iosFDXy0wgbfFdr5PtugjFBSu0B-E47bld6OPyYfTEo,2672
|
|
8
|
+
recall_livekit/tools.py,sha256=sV87Fy_JEh8jKCwcTr2cQZg_1ZrIktTPijsMVLR-y_k,5718
|
|
9
|
+
recall_livekit-0.1.0.dist-info/METADATA,sha256=ZQIMlO0BIRJJEPt-nM3x-5PIqZEvs-RCgBYnanTAD1k,7098
|
|
10
|
+
recall_livekit-0.1.0.dist-info/WHEEL,sha256=THafob7ofN-NsuMN7Mg4qZyHaQI7KkD-QlcQatYhXPo,87
|
|
11
|
+
recall_livekit-0.1.0.dist-info/licenses/LICENSE,sha256=ra9FdQ2xyykGuwkTiZDGe8MaUdF61EbNfS6xW16vQUY,11343
|
|
12
|
+
recall_livekit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Polign, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|