@elizaos/python 2.0.0-alpha.11 → 2.0.0-alpha.26
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.
- package/elizaos/advanced_capabilities/__init__.py +6 -41
- package/elizaos/advanced_capabilities/actions/__init__.py +1 -21
- package/elizaos/advanced_capabilities/actions/add_contact.py +21 -11
- package/elizaos/advanced_capabilities/actions/follow_room.py +28 -28
- package/elizaos/advanced_capabilities/actions/image_generation.py +13 -26
- package/elizaos/advanced_capabilities/actions/mute_room.py +13 -26
- package/elizaos/advanced_capabilities/actions/remove_contact.py +16 -2
- package/elizaos/advanced_capabilities/actions/roles.py +13 -27
- package/elizaos/advanced_capabilities/actions/search_contacts.py +17 -3
- package/elizaos/advanced_capabilities/actions/send_message.py +317 -9
- package/elizaos/advanced_capabilities/actions/settings.py +16 -2
- package/elizaos/advanced_capabilities/actions/unfollow_room.py +13 -26
- package/elizaos/advanced_capabilities/actions/unmute_room.py +13 -26
- package/elizaos/advanced_capabilities/actions/update_contact.py +16 -2
- package/elizaos/advanced_capabilities/actions/update_entity.py +16 -2
- package/elizaos/advanced_capabilities/evaluators/__init__.py +2 -9
- package/elizaos/advanced_capabilities/evaluators/reflection.py +3 -132
- package/elizaos/advanced_capabilities/evaluators/relationship_extraction.py +5 -201
- package/elizaos/advanced_capabilities/providers/__init__.py +1 -12
- package/elizaos/advanced_capabilities/providers/knowledge.py +24 -3
- package/elizaos/advanced_capabilities/services/__init__.py +2 -9
- package/elizaos/advanced_memory/actions/reset_session.py +11 -0
- package/elizaos/advanced_memory/evaluators/reflection.py +134 -0
- package/elizaos/advanced_memory/evaluators/relationship_extraction.py +203 -0
- package/elizaos/advanced_memory/test_advanced_memory.py +357 -0
- package/elizaos/advanced_planning/actions/schedule_follow_up.py +222 -0
- package/elizaos/basic_capabilities/__init__.py +0 -2
- package/elizaos/basic_capabilities/providers/__init__.py +0 -3
- package/elizaos/basic_capabilities/providers/agent_settings.py +64 -0
- package/elizaos/basic_capabilities/providers/contacts.py +79 -0
- package/elizaos/basic_capabilities/providers/facts.py +87 -0
- package/elizaos/basic_capabilities/providers/follow_ups.py +117 -0
- package/elizaos/basic_capabilities/providers/knowledge.py +97 -0
- package/elizaos/basic_capabilities/providers/relationships.py +107 -0
- package/elizaos/basic_capabilities/providers/roles.py +96 -0
- package/elizaos/basic_capabilities/providers/settings.py +56 -0
- package/elizaos/bootstrap/autonomy/__init__.py +5 -1
- package/elizaos/bootstrap/autonomy/action.py +161 -0
- package/elizaos/bootstrap/autonomy/evaluators.py +217 -0
- package/elizaos/bootstrap/autonomy/service.py +8 -0
- package/elizaos/bootstrap/plugin.py +7 -0
- package/elizaos/bootstrap/providers/knowledge.py +26 -3
- package/elizaos/bootstrap/services/embedding.py +156 -1
- package/elizaos/runtime.py +63 -18
- package/elizaos/services/message_service.py +173 -23
- package/elizaos/types/generated/eliza/v1/agent_pb2.py +16 -16
- package/elizaos/types/generated/eliza/v1/agent_pb2.pyi +2 -4
- package/elizaos/types/model.py +27 -0
- package/elizaos/types/runtime.py +5 -1
- package/elizaos/utils/validation.py +76 -0
- package/package.json +2 -2
- package/tests/test_actions_provider_examples.py +58 -1
- package/tests/test_async_embedding.py +124 -0
- package/tests/test_autonomy.py +13 -2
- package/tests/test_validation.py +141 -0
- package/tests/verify_memory_architecture.py +192 -0
- package/elizaos/basic_capabilities/providers/capabilities.py +0 -62
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"""Tests for the advanced memory module.
|
|
2
|
+
|
|
3
|
+
Covers XML parsing, extraction checkpointing, config management,
|
|
4
|
+
confidence sorting, and formatted memory output.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from uuid import uuid4
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
from .memory_service import (
|
|
14
|
+
MemoryService,
|
|
15
|
+
_parse_memory_extraction_xml,
|
|
16
|
+
_parse_summary_xml,
|
|
17
|
+
_top_k_by_confidence,
|
|
18
|
+
)
|
|
19
|
+
from .types import (
|
|
20
|
+
LongTermMemory,
|
|
21
|
+
LongTermMemoryCategory,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# ============================================================================
|
|
25
|
+
# XML Parsing: Summary
|
|
26
|
+
# ============================================================================
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TestParseSummaryXml:
|
|
30
|
+
def test_valid_xml(self):
|
|
31
|
+
xml = """
|
|
32
|
+
<summary>
|
|
33
|
+
<text>The user discussed their favorite coffee.</text>
|
|
34
|
+
<topics>coffee, preferences, beverages</topics>
|
|
35
|
+
<key_points>
|
|
36
|
+
<point>User prefers dark roast</point>
|
|
37
|
+
<point>User drinks 3 cups daily</point>
|
|
38
|
+
</key_points>
|
|
39
|
+
</summary>"""
|
|
40
|
+
result = _parse_summary_xml(xml)
|
|
41
|
+
assert result.summary == "The user discussed their favorite coffee."
|
|
42
|
+
assert result.topics == ["coffee", "preferences", "beverages"]
|
|
43
|
+
assert len(result.key_points) == 2
|
|
44
|
+
assert result.key_points[0] == "User prefers dark roast"
|
|
45
|
+
assert result.key_points[1] == "User drinks 3 cups daily"
|
|
46
|
+
|
|
47
|
+
def test_malformed_xml(self):
|
|
48
|
+
result = _parse_summary_xml("This is not XML at all")
|
|
49
|
+
assert result.summary == "Summary not available"
|
|
50
|
+
assert result.topics == []
|
|
51
|
+
assert result.key_points == []
|
|
52
|
+
|
|
53
|
+
def test_partial_tags(self):
|
|
54
|
+
result = _parse_summary_xml("<text>Just a summary</text>")
|
|
55
|
+
assert result.summary == "Just a summary"
|
|
56
|
+
assert result.topics == []
|
|
57
|
+
assert result.key_points == []
|
|
58
|
+
|
|
59
|
+
def test_empty_topics(self):
|
|
60
|
+
result = _parse_summary_xml("<text>Summary here</text><topics></topics>")
|
|
61
|
+
assert result.summary == "Summary here"
|
|
62
|
+
assert result.topics == []
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ============================================================================
|
|
66
|
+
# XML Parsing: Memory Extraction
|
|
67
|
+
# ============================================================================
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class TestParseMemoryExtractionXml:
|
|
71
|
+
def test_valid_multiple(self):
|
|
72
|
+
xml = """
|
|
73
|
+
<memories>
|
|
74
|
+
<memory>
|
|
75
|
+
<category>semantic</category>
|
|
76
|
+
<content>User works as a software engineer</content>
|
|
77
|
+
<confidence>0.95</confidence>
|
|
78
|
+
</memory>
|
|
79
|
+
<memory>
|
|
80
|
+
<category>episodic</category>
|
|
81
|
+
<content>User had a meeting yesterday</content>
|
|
82
|
+
<confidence>0.8</confidence>
|
|
83
|
+
</memory>
|
|
84
|
+
<memory>
|
|
85
|
+
<category>procedural</category>
|
|
86
|
+
<content>User prefers TypeScript for backend</content>
|
|
87
|
+
<confidence>0.9</confidence>
|
|
88
|
+
</memory>
|
|
89
|
+
</memories>"""
|
|
90
|
+
extractions = _parse_memory_extraction_xml(xml)
|
|
91
|
+
assert len(extractions) == 3
|
|
92
|
+
assert extractions[0].category == LongTermMemoryCategory.SEMANTIC
|
|
93
|
+
assert extractions[0].content == "User works as a software engineer"
|
|
94
|
+
assert abs(extractions[0].confidence - 0.95) < 0.001
|
|
95
|
+
assert extractions[1].category == LongTermMemoryCategory.EPISODIC
|
|
96
|
+
assert extractions[2].category == LongTermMemoryCategory.PROCEDURAL
|
|
97
|
+
|
|
98
|
+
def test_invalid_category_skipped(self):
|
|
99
|
+
xml = """
|
|
100
|
+
<memories>
|
|
101
|
+
<memory>
|
|
102
|
+
<category>invalid_type</category>
|
|
103
|
+
<content>This should be skipped</content>
|
|
104
|
+
<confidence>0.9</confidence>
|
|
105
|
+
</memory>
|
|
106
|
+
<memory>
|
|
107
|
+
<category>semantic</category>
|
|
108
|
+
<content>This should be kept</content>
|
|
109
|
+
<confidence>0.85</confidence>
|
|
110
|
+
</memory>
|
|
111
|
+
</memories>"""
|
|
112
|
+
extractions = _parse_memory_extraction_xml(xml)
|
|
113
|
+
assert len(extractions) == 1
|
|
114
|
+
assert extractions[0].content == "This should be kept"
|
|
115
|
+
|
|
116
|
+
def test_bad_confidence_skipped(self):
|
|
117
|
+
xml = """
|
|
118
|
+
<memory>
|
|
119
|
+
<category>semantic</category>
|
|
120
|
+
<content>Bad confidence</content>
|
|
121
|
+
<confidence>not_a_number</confidence>
|
|
122
|
+
</memory>"""
|
|
123
|
+
extractions = _parse_memory_extraction_xml(xml)
|
|
124
|
+
assert len(extractions) == 0
|
|
125
|
+
|
|
126
|
+
def test_empty_input(self):
|
|
127
|
+
assert _parse_memory_extraction_xml("") == []
|
|
128
|
+
|
|
129
|
+
def test_no_memories(self):
|
|
130
|
+
assert _parse_memory_extraction_xml("The model didn't return structured data.") == []
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# ============================================================================
|
|
134
|
+
# top_k_by_confidence
|
|
135
|
+
# ============================================================================
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class TestTopKByConfidence:
|
|
139
|
+
def test_sorts_by_confidence(self):
|
|
140
|
+
entity_id = uuid4()
|
|
141
|
+
agent_id = uuid4()
|
|
142
|
+
memories = [
|
|
143
|
+
LongTermMemory(
|
|
144
|
+
id=uuid4(),
|
|
145
|
+
agent_id=agent_id,
|
|
146
|
+
entity_id=entity_id,
|
|
147
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
148
|
+
content="low",
|
|
149
|
+
confidence=0.5,
|
|
150
|
+
),
|
|
151
|
+
LongTermMemory(
|
|
152
|
+
id=uuid4(),
|
|
153
|
+
agent_id=agent_id,
|
|
154
|
+
entity_id=entity_id,
|
|
155
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
156
|
+
content="high",
|
|
157
|
+
confidence=0.95,
|
|
158
|
+
),
|
|
159
|
+
LongTermMemory(
|
|
160
|
+
id=uuid4(),
|
|
161
|
+
agent_id=agent_id,
|
|
162
|
+
entity_id=entity_id,
|
|
163
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
164
|
+
content="mid",
|
|
165
|
+
confidence=0.8,
|
|
166
|
+
),
|
|
167
|
+
]
|
|
168
|
+
result = _top_k_by_confidence(memories, 2)
|
|
169
|
+
assert len(result) == 2
|
|
170
|
+
assert result[0].content == "high"
|
|
171
|
+
assert result[1].content == "mid"
|
|
172
|
+
|
|
173
|
+
def test_zero_limit(self):
|
|
174
|
+
entity_id = uuid4()
|
|
175
|
+
agent_id = uuid4()
|
|
176
|
+
memories = [
|
|
177
|
+
LongTermMemory(
|
|
178
|
+
id=uuid4(),
|
|
179
|
+
agent_id=agent_id,
|
|
180
|
+
entity_id=entity_id,
|
|
181
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
182
|
+
content="x",
|
|
183
|
+
confidence=0.9,
|
|
184
|
+
),
|
|
185
|
+
]
|
|
186
|
+
assert _top_k_by_confidence(memories, 0) == []
|
|
187
|
+
|
|
188
|
+
def test_empty_list(self):
|
|
189
|
+
assert _top_k_by_confidence([], 5) == []
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ============================================================================
|
|
193
|
+
# Config Management
|
|
194
|
+
# ============================================================================
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class TestConfigManagement:
|
|
198
|
+
def test_defaults_are_sensible(self):
|
|
199
|
+
svc = MemoryService()
|
|
200
|
+
config = svc.get_config()
|
|
201
|
+
assert config.short_term_summarization_threshold > 0
|
|
202
|
+
assert config.long_term_extraction_threshold > 0
|
|
203
|
+
assert config.long_term_extraction_interval > 0
|
|
204
|
+
assert config.long_term_confidence_threshold > 0.0
|
|
205
|
+
|
|
206
|
+
def test_get_config_returns_copy(self):
|
|
207
|
+
svc = MemoryService()
|
|
208
|
+
c1 = svc.get_config()
|
|
209
|
+
c1.short_term_summarization_threshold = 99999
|
|
210
|
+
c2 = svc.get_config()
|
|
211
|
+
assert c2.short_term_summarization_threshold != 99999
|
|
212
|
+
|
|
213
|
+
def test_update_config_partial(self):
|
|
214
|
+
svc = MemoryService()
|
|
215
|
+
original = svc.get_config()
|
|
216
|
+
svc._config.short_term_summarization_threshold = 999
|
|
217
|
+
updated = svc.get_config()
|
|
218
|
+
assert updated.short_term_summarization_threshold == 999
|
|
219
|
+
# Other fields preserved
|
|
220
|
+
assert updated.long_term_extraction_threshold == original.long_term_extraction_threshold
|
|
221
|
+
assert updated.long_term_extraction_interval == original.long_term_extraction_interval
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# ============================================================================
|
|
225
|
+
# Extraction Checkpointing
|
|
226
|
+
# ============================================================================
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class TestExtractionCheckpointing:
|
|
230
|
+
@pytest.mark.asyncio
|
|
231
|
+
async def test_below_threshold_does_not_run(self):
|
|
232
|
+
svc = MemoryService()
|
|
233
|
+
entity = uuid4()
|
|
234
|
+
room = uuid4()
|
|
235
|
+
assert not await svc.should_run_extraction(entity, room, 1)
|
|
236
|
+
|
|
237
|
+
@pytest.mark.asyncio
|
|
238
|
+
async def test_at_threshold_runs_first_time(self):
|
|
239
|
+
svc = MemoryService()
|
|
240
|
+
config = svc.get_config()
|
|
241
|
+
entity = uuid4()
|
|
242
|
+
room = uuid4()
|
|
243
|
+
assert await svc.should_run_extraction(entity, room, config.long_term_extraction_threshold)
|
|
244
|
+
|
|
245
|
+
@pytest.mark.asyncio
|
|
246
|
+
async def test_checkpoint_prevents_rerun(self):
|
|
247
|
+
svc = MemoryService()
|
|
248
|
+
config = svc.get_config()
|
|
249
|
+
threshold = config.long_term_extraction_threshold
|
|
250
|
+
entity = uuid4()
|
|
251
|
+
room = uuid4()
|
|
252
|
+
await svc.set_last_extraction_checkpoint(entity, room, threshold)
|
|
253
|
+
assert not await svc.should_run_extraction(entity, room, threshold)
|
|
254
|
+
|
|
255
|
+
@pytest.mark.asyncio
|
|
256
|
+
async def test_next_interval_runs(self):
|
|
257
|
+
svc = MemoryService()
|
|
258
|
+
config = svc.get_config()
|
|
259
|
+
threshold = config.long_term_extraction_threshold
|
|
260
|
+
interval = config.long_term_extraction_interval
|
|
261
|
+
entity = uuid4()
|
|
262
|
+
room = uuid4()
|
|
263
|
+
await svc.set_last_extraction_checkpoint(entity, room, threshold)
|
|
264
|
+
assert await svc.should_run_extraction(entity, room, threshold + interval)
|
|
265
|
+
|
|
266
|
+
@pytest.mark.asyncio
|
|
267
|
+
async def test_independent_entity_room_pairs(self):
|
|
268
|
+
svc = MemoryService()
|
|
269
|
+
config = svc.get_config()
|
|
270
|
+
threshold = config.long_term_extraction_threshold
|
|
271
|
+
entity_a = uuid4()
|
|
272
|
+
entity_b = uuid4()
|
|
273
|
+
room = uuid4()
|
|
274
|
+
await svc.set_last_extraction_checkpoint(entity_a, room, threshold)
|
|
275
|
+
# entity_b should still be eligible
|
|
276
|
+
assert await svc.should_run_extraction(entity_b, room, threshold)
|
|
277
|
+
# entity_a should not
|
|
278
|
+
assert not await svc.should_run_extraction(entity_a, room, threshold)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
# ============================================================================
|
|
282
|
+
# Formatted Memory Output
|
|
283
|
+
# ============================================================================
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class TestFormattedLongTermMemories:
|
|
287
|
+
@pytest.mark.asyncio
|
|
288
|
+
async def test_groups_by_category(self):
|
|
289
|
+
svc = MemoryService()
|
|
290
|
+
entity_id = uuid4()
|
|
291
|
+
agent_id = uuid4()
|
|
292
|
+
|
|
293
|
+
# Manually inject memories into fallback storage
|
|
294
|
+
key = str(entity_id)
|
|
295
|
+
svc._long_term[key] = [
|
|
296
|
+
LongTermMemory(
|
|
297
|
+
id=uuid4(),
|
|
298
|
+
agent_id=agent_id,
|
|
299
|
+
entity_id=entity_id,
|
|
300
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
301
|
+
content="Likes coffee",
|
|
302
|
+
confidence=0.9,
|
|
303
|
+
),
|
|
304
|
+
LongTermMemory(
|
|
305
|
+
id=uuid4(),
|
|
306
|
+
agent_id=agent_id,
|
|
307
|
+
entity_id=entity_id,
|
|
308
|
+
category=LongTermMemoryCategory.EPISODIC,
|
|
309
|
+
content="Had meeting",
|
|
310
|
+
confidence=0.85,
|
|
311
|
+
),
|
|
312
|
+
LongTermMemory(
|
|
313
|
+
id=uuid4(),
|
|
314
|
+
agent_id=agent_id,
|
|
315
|
+
entity_id=entity_id,
|
|
316
|
+
category=LongTermMemoryCategory.SEMANTIC,
|
|
317
|
+
content="Prefers dark mode",
|
|
318
|
+
confidence=0.88,
|
|
319
|
+
),
|
|
320
|
+
]
|
|
321
|
+
|
|
322
|
+
result = await svc.get_formatted_long_term_memories(entity_id)
|
|
323
|
+
assert "**Semantic**:" in result
|
|
324
|
+
assert "**Episodic**:" in result
|
|
325
|
+
assert "- Likes coffee" in result
|
|
326
|
+
assert "- Prefers dark mode" in result
|
|
327
|
+
assert "- Had meeting" in result
|
|
328
|
+
|
|
329
|
+
@pytest.mark.asyncio
|
|
330
|
+
async def test_empty_returns_empty_string(self):
|
|
331
|
+
svc = MemoryService()
|
|
332
|
+
entity_id = uuid4()
|
|
333
|
+
result = await svc.get_formatted_long_term_memories(entity_id)
|
|
334
|
+
assert result == ""
|
|
335
|
+
|
|
336
|
+
@pytest.mark.asyncio
|
|
337
|
+
async def test_single_category(self):
|
|
338
|
+
svc = MemoryService()
|
|
339
|
+
entity_id = uuid4()
|
|
340
|
+
agent_id = uuid4()
|
|
341
|
+
|
|
342
|
+
svc._long_term[str(entity_id)] = [
|
|
343
|
+
LongTermMemory(
|
|
344
|
+
id=uuid4(),
|
|
345
|
+
agent_id=agent_id,
|
|
346
|
+
entity_id=entity_id,
|
|
347
|
+
category=LongTermMemoryCategory.PROCEDURAL,
|
|
348
|
+
content="Knows how to ride a bike",
|
|
349
|
+
confidence=0.95,
|
|
350
|
+
),
|
|
351
|
+
]
|
|
352
|
+
|
|
353
|
+
result = await svc.get_formatted_long_term_memories(entity_id)
|
|
354
|
+
assert "**Procedural**:" in result
|
|
355
|
+
assert "- Knows how to ride a bike" in result
|
|
356
|
+
assert "**Semantic**:" not in result
|
|
357
|
+
assert "**Episodic**:" not in result
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
from uuid import UUID as StdUUID
|
|
7
|
+
|
|
8
|
+
from elizaos.bootstrap.utils.xml import parse_key_value_xml
|
|
9
|
+
from elizaos.deterministic import get_prompt_reference_datetime
|
|
10
|
+
from elizaos.generated.spec_helpers import require_action_spec
|
|
11
|
+
from elizaos.prompts import SCHEDULE_FOLLOW_UP_TEMPLATE
|
|
12
|
+
from elizaos.types import (
|
|
13
|
+
Action,
|
|
14
|
+
ActionExample,
|
|
15
|
+
ActionResult,
|
|
16
|
+
Content,
|
|
17
|
+
ModelType,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from elizaos.types import (
|
|
22
|
+
HandlerCallback,
|
|
23
|
+
HandlerOptions,
|
|
24
|
+
IAgentRuntime,
|
|
25
|
+
Memory,
|
|
26
|
+
State,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Get text content from centralized specs
|
|
30
|
+
_spec = require_action_spec("SCHEDULE_FOLLOW_UP")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _convert_spec_examples() -> list[list[ActionExample]]:
|
|
34
|
+
"""Convert spec examples to ActionExample format."""
|
|
35
|
+
spec_examples = _spec.get("examples", [])
|
|
36
|
+
if spec_examples:
|
|
37
|
+
return [
|
|
38
|
+
[
|
|
39
|
+
ActionExample(
|
|
40
|
+
name=msg.get("name", ""),
|
|
41
|
+
content=Content(
|
|
42
|
+
text=msg.get("content", {}).get("text", ""),
|
|
43
|
+
actions=msg.get("content", {}).get("actions"),
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
for msg in example
|
|
47
|
+
]
|
|
48
|
+
for example in spec_examples
|
|
49
|
+
]
|
|
50
|
+
return []
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _normalize_priority(raw_priority: str) -> str:
|
|
54
|
+
normalized = raw_priority.strip().lower()
|
|
55
|
+
if normalized in {"high", "medium", "low"}:
|
|
56
|
+
return normalized
|
|
57
|
+
return "medium"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _coerce_uuid(value: object | None) -> StdUUID | None:
|
|
61
|
+
if value is None:
|
|
62
|
+
return None
|
|
63
|
+
text = str(value).strip()
|
|
64
|
+
if not text:
|
|
65
|
+
return None
|
|
66
|
+
try:
|
|
67
|
+
return StdUUID(text)
|
|
68
|
+
except ValueError:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class ScheduleFollowUpAction:
|
|
74
|
+
name: str = _spec["name"]
|
|
75
|
+
similes: list[str] = field(default_factory=lambda: list(_spec.get("similes", [])))
|
|
76
|
+
description: str = _spec["description"]
|
|
77
|
+
|
|
78
|
+
async def validate(
|
|
79
|
+
self, runtime: IAgentRuntime, _message: Memory, _state: State | None = None
|
|
80
|
+
) -> bool:
|
|
81
|
+
rolodex_service = runtime.get_service("rolodex")
|
|
82
|
+
follow_up_service = runtime.get_service("follow_up")
|
|
83
|
+
return rolodex_service is not None and follow_up_service is not None
|
|
84
|
+
|
|
85
|
+
async def handler(
|
|
86
|
+
self,
|
|
87
|
+
runtime: IAgentRuntime,
|
|
88
|
+
message: Memory,
|
|
89
|
+
state: State | None = None,
|
|
90
|
+
options: HandlerOptions | None = None,
|
|
91
|
+
callback: HandlerCallback | None = None,
|
|
92
|
+
responses: list[Memory] | None = None,
|
|
93
|
+
) -> ActionResult:
|
|
94
|
+
from elizaos.bootstrap.services.follow_up import FollowUpService
|
|
95
|
+
from elizaos.bootstrap.services.rolodex import RolodexService
|
|
96
|
+
|
|
97
|
+
rolodex_service = runtime.get_service("rolodex")
|
|
98
|
+
follow_up_service = runtime.get_service("follow_up")
|
|
99
|
+
|
|
100
|
+
if not rolodex_service or not isinstance(rolodex_service, RolodexService):
|
|
101
|
+
return ActionResult(
|
|
102
|
+
text="Rolodex service not available",
|
|
103
|
+
success=False,
|
|
104
|
+
values={"error": True},
|
|
105
|
+
data={"error": "RolodexService not available"},
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if not follow_up_service or not isinstance(follow_up_service, FollowUpService):
|
|
109
|
+
return ActionResult(
|
|
110
|
+
text="Follow-up service not available",
|
|
111
|
+
success=False,
|
|
112
|
+
values={"error": True},
|
|
113
|
+
data={"error": "FollowUpService not available"},
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
state = await runtime.compose_state(message, ["RECENT_MESSAGES", "ENTITIES"])
|
|
117
|
+
state.values["currentDateTime"] = get_prompt_reference_datetime(
|
|
118
|
+
runtime,
|
|
119
|
+
message,
|
|
120
|
+
state,
|
|
121
|
+
"action:schedule_follow_up",
|
|
122
|
+
).isoformat()
|
|
123
|
+
|
|
124
|
+
prompt = runtime.compose_prompt_from_state(
|
|
125
|
+
state=state,
|
|
126
|
+
template=SCHEDULE_FOLLOW_UP_TEMPLATE,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
response = await runtime.use_model(ModelType.TEXT_SMALL, {"prompt": prompt})
|
|
130
|
+
parsed = parse_key_value_xml(response)
|
|
131
|
+
|
|
132
|
+
if not parsed or not parsed.get("contactName"):
|
|
133
|
+
return ActionResult(
|
|
134
|
+
text="Could not extract follow-up information",
|
|
135
|
+
success=False,
|
|
136
|
+
values={"error": True},
|
|
137
|
+
data={"error": "Failed to parse follow-up info"},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
contact_name = str(parsed.get("contactName", ""))
|
|
141
|
+
scheduled_at_str = str(parsed.get("scheduledAt", ""))
|
|
142
|
+
reason = str(parsed.get("reason", "Follow-up"))
|
|
143
|
+
priority = _normalize_priority(str(parsed.get("priority", "medium")))
|
|
144
|
+
follow_up_message = str(parsed.get("message", ""))
|
|
145
|
+
parsed_entity_id = _coerce_uuid(parsed.get("entityId"))
|
|
146
|
+
message_entity_id = _coerce_uuid(message.entity_id)
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
scheduled_at = datetime.fromisoformat(scheduled_at_str.replace("Z", "+00:00"))
|
|
150
|
+
except ValueError:
|
|
151
|
+
return ActionResult(
|
|
152
|
+
text="Could not parse the follow-up date/time",
|
|
153
|
+
success=False,
|
|
154
|
+
values={"error": True},
|
|
155
|
+
data={"error": "Invalid follow-up datetime"},
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
entity_id_uuid = parsed_entity_id or message_entity_id
|
|
159
|
+
if entity_id_uuid is None and contact_name:
|
|
160
|
+
contacts = await rolodex_service.search_contacts(search_term=contact_name)
|
|
161
|
+
if contacts:
|
|
162
|
+
entity_id_uuid = contacts[0].entity_id
|
|
163
|
+
|
|
164
|
+
if entity_id_uuid is None:
|
|
165
|
+
return ActionResult(
|
|
166
|
+
text=f"Could not determine which contact to schedule for ({contact_name}).",
|
|
167
|
+
success=False,
|
|
168
|
+
values={"error": True},
|
|
169
|
+
data={"error": "Missing contact entity id"},
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
contact = await rolodex_service.get_contact(entity_id_uuid)
|
|
173
|
+
if contact is None:
|
|
174
|
+
return ActionResult(
|
|
175
|
+
text=f"Contact '{contact_name}' was not found in the rolodex.",
|
|
176
|
+
success=False,
|
|
177
|
+
values={"error": True},
|
|
178
|
+
data={"error": "Contact not found"},
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
await follow_up_service.schedule_follow_up(
|
|
182
|
+
entity_id=entity_id_uuid,
|
|
183
|
+
scheduled_at=scheduled_at,
|
|
184
|
+
reason=reason,
|
|
185
|
+
priority=priority,
|
|
186
|
+
message=follow_up_message,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
response_text = f"I've scheduled a follow-up with {contact_name} for {scheduled_at.strftime('%B %d, %Y')}. Reason: {reason}"
|
|
190
|
+
|
|
191
|
+
if callback:
|
|
192
|
+
await callback(Content(text=response_text, actions=["SCHEDULE_FOLLOW_UP"]))
|
|
193
|
+
|
|
194
|
+
return ActionResult(
|
|
195
|
+
text=response_text,
|
|
196
|
+
success=True,
|
|
197
|
+
values={
|
|
198
|
+
"contactId": str(entity_id_uuid),
|
|
199
|
+
"scheduledAt": scheduled_at.isoformat(),
|
|
200
|
+
},
|
|
201
|
+
data={
|
|
202
|
+
"contactId": str(entity_id_uuid),
|
|
203
|
+
"contactName": contact_name,
|
|
204
|
+
"scheduledAt": scheduled_at.isoformat(),
|
|
205
|
+
"reason": reason,
|
|
206
|
+
"priority": priority,
|
|
207
|
+
},
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def examples(self) -> list[list[ActionExample]]:
|
|
212
|
+
return _convert_spec_examples()
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
schedule_follow_up_action = Action(
|
|
216
|
+
name=ScheduleFollowUpAction.name,
|
|
217
|
+
similes=ScheduleFollowUpAction().similes,
|
|
218
|
+
description=ScheduleFollowUpAction.description,
|
|
219
|
+
validate=ScheduleFollowUpAction().validate,
|
|
220
|
+
handler=ScheduleFollowUpAction().handler,
|
|
221
|
+
examples=ScheduleFollowUpAction().examples,
|
|
222
|
+
)
|
|
@@ -18,7 +18,6 @@ from .providers import (
|
|
|
18
18
|
actions_provider,
|
|
19
19
|
attachments_provider,
|
|
20
20
|
basic_providers,
|
|
21
|
-
capabilities_provider,
|
|
22
21
|
character_provider,
|
|
23
22
|
choice_provider,
|
|
24
23
|
context_bench_provider,
|
|
@@ -48,7 +47,6 @@ __all__ = [
|
|
|
48
47
|
"action_state_provider",
|
|
49
48
|
"actions_provider",
|
|
50
49
|
"attachments_provider",
|
|
51
|
-
"capabilities_provider",
|
|
52
50
|
"character_provider",
|
|
53
51
|
"choice_provider",
|
|
54
52
|
"context_bench_provider",
|
|
@@ -6,7 +6,6 @@ Fundamental providers included by default in the bootstrap plugin.
|
|
|
6
6
|
from .action_state import action_state_provider
|
|
7
7
|
from .actions import actions_provider
|
|
8
8
|
from .attachments import attachments_provider
|
|
9
|
-
from .capabilities import capabilities_provider
|
|
10
9
|
from .character import character_provider
|
|
11
10
|
from .choice import choice_provider
|
|
12
11
|
from .context_bench import context_bench_provider
|
|
@@ -22,7 +21,6 @@ __all__ = [
|
|
|
22
21
|
"action_state_provider",
|
|
23
22
|
"actions_provider",
|
|
24
23
|
"attachments_provider",
|
|
25
|
-
"capabilities_provider",
|
|
26
24
|
"character_provider",
|
|
27
25
|
"choice_provider",
|
|
28
26
|
"context_bench_provider",
|
|
@@ -40,7 +38,6 @@ basic_providers = [
|
|
|
40
38
|
actions_provider,
|
|
41
39
|
action_state_provider,
|
|
42
40
|
attachments_provider,
|
|
43
|
-
capabilities_provider,
|
|
44
41
|
character_provider,
|
|
45
42
|
choice_provider,
|
|
46
43
|
context_bench_provider,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from elizaos.generated.spec_helpers import require_provider_spec
|
|
6
|
+
from elizaos.types import Provider, ProviderResult
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from elizaos.types import IAgentRuntime, Memory, State
|
|
10
|
+
|
|
11
|
+
# Get text content from centralized specs
|
|
12
|
+
_spec = require_provider_spec("AGENT_SETTINGS")
|
|
13
|
+
|
|
14
|
+
SENSITIVE_KEY_PATTERNS = (
|
|
15
|
+
"key",
|
|
16
|
+
"secret",
|
|
17
|
+
"password",
|
|
18
|
+
"token",
|
|
19
|
+
"credential",
|
|
20
|
+
"auth",
|
|
21
|
+
"private",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def get_agent_settings_context(
|
|
26
|
+
runtime: IAgentRuntime,
|
|
27
|
+
message: Memory,
|
|
28
|
+
state: State | None = None,
|
|
29
|
+
) -> ProviderResult:
|
|
30
|
+
all_settings = runtime.get_all_settings()
|
|
31
|
+
|
|
32
|
+
safe_settings: dict[str, str] = {}
|
|
33
|
+
for key, value in all_settings.items():
|
|
34
|
+
if not any(pattern in key.lower() for pattern in SENSITIVE_KEY_PATTERNS):
|
|
35
|
+
safe_settings[key] = str(value)
|
|
36
|
+
|
|
37
|
+
sections: list[str] = []
|
|
38
|
+
if safe_settings:
|
|
39
|
+
sections.append("# Agent Settings")
|
|
40
|
+
for key, value in safe_settings.items():
|
|
41
|
+
display_value = value if len(value) <= 50 else value[:50] + "..."
|
|
42
|
+
sections.append(f"- {key}: {display_value}")
|
|
43
|
+
|
|
44
|
+
context_text = "\n".join(sections) if sections else ""
|
|
45
|
+
|
|
46
|
+
return ProviderResult(
|
|
47
|
+
text=context_text,
|
|
48
|
+
values={
|
|
49
|
+
"settingsCount": len(safe_settings),
|
|
50
|
+
"hasSettings": len(safe_settings) > 0,
|
|
51
|
+
},
|
|
52
|
+
data={
|
|
53
|
+
"settings": safe_settings,
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
agent_settings_provider = Provider(
|
|
59
|
+
name=_spec["name"],
|
|
60
|
+
description=_spec["description"],
|
|
61
|
+
get=get_agent_settings_context,
|
|
62
|
+
dynamic=_spec.get("dynamic", True),
|
|
63
|
+
position=_spec.get("position"),
|
|
64
|
+
)
|