@elizaos/python 2.0.0-alpha.10
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/LICENSE +26 -0
- package/README.md +239 -0
- package/elizaos/__init__.py +280 -0
- package/elizaos/action_docs.py +149 -0
- package/elizaos/advanced_capabilities/__init__.py +85 -0
- package/elizaos/advanced_capabilities/actions/__init__.py +54 -0
- package/elizaos/advanced_capabilities/actions/add_contact.py +139 -0
- package/elizaos/advanced_capabilities/actions/follow_room.py +151 -0
- package/elizaos/advanced_capabilities/actions/image_generation.py +148 -0
- package/elizaos/advanced_capabilities/actions/mute_room.py +164 -0
- package/elizaos/advanced_capabilities/actions/remove_contact.py +145 -0
- package/elizaos/advanced_capabilities/actions/roles.py +207 -0
- package/elizaos/advanced_capabilities/actions/schedule_follow_up.py +154 -0
- package/elizaos/advanced_capabilities/actions/search_contacts.py +145 -0
- package/elizaos/advanced_capabilities/actions/send_message.py +187 -0
- package/elizaos/advanced_capabilities/actions/settings.py +151 -0
- package/elizaos/advanced_capabilities/actions/unfollow_room.py +164 -0
- package/elizaos/advanced_capabilities/actions/unmute_room.py +164 -0
- package/elizaos/advanced_capabilities/actions/update_contact.py +164 -0
- package/elizaos/advanced_capabilities/actions/update_entity.py +161 -0
- package/elizaos/advanced_capabilities/evaluators/__init__.py +18 -0
- package/elizaos/advanced_capabilities/evaluators/reflection.py +134 -0
- package/elizaos/advanced_capabilities/evaluators/relationship_extraction.py +203 -0
- package/elizaos/advanced_capabilities/providers/__init__.py +36 -0
- package/elizaos/advanced_capabilities/providers/agent_settings.py +60 -0
- package/elizaos/advanced_capabilities/providers/contacts.py +77 -0
- package/elizaos/advanced_capabilities/providers/facts.py +82 -0
- package/elizaos/advanced_capabilities/providers/follow_ups.py +113 -0
- package/elizaos/advanced_capabilities/providers/knowledge.py +83 -0
- package/elizaos/advanced_capabilities/providers/relationships.py +112 -0
- package/elizaos/advanced_capabilities/providers/roles.py +97 -0
- package/elizaos/advanced_capabilities/providers/settings.py +51 -0
- package/elizaos/advanced_capabilities/services/__init__.py +18 -0
- package/elizaos/advanced_capabilities/services/follow_up.py +138 -0
- package/elizaos/advanced_capabilities/services/rolodex.py +244 -0
- package/elizaos/advanced_memory/__init__.py +3 -0
- package/elizaos/advanced_memory/evaluators.py +97 -0
- package/elizaos/advanced_memory/memory_service.py +556 -0
- package/elizaos/advanced_memory/plugin.py +30 -0
- package/elizaos/advanced_memory/prompts.py +12 -0
- package/elizaos/advanced_memory/providers.py +90 -0
- package/elizaos/advanced_memory/types.py +65 -0
- package/elizaos/advanced_planning/__init__.py +10 -0
- package/elizaos/advanced_planning/actions.py +145 -0
- package/elizaos/advanced_planning/message_classifier.py +127 -0
- package/elizaos/advanced_planning/planning_service.py +712 -0
- package/elizaos/advanced_planning/plugin.py +40 -0
- package/elizaos/advanced_planning/prompts.py +4 -0
- package/elizaos/basic_capabilities/__init__.py +66 -0
- package/elizaos/basic_capabilities/actions/__init__.py +24 -0
- package/elizaos/basic_capabilities/actions/choice.py +140 -0
- package/elizaos/basic_capabilities/actions/ignore.py +66 -0
- package/elizaos/basic_capabilities/actions/none.py +56 -0
- package/elizaos/basic_capabilities/actions/reply.py +120 -0
- package/elizaos/basic_capabilities/providers/__init__.py +54 -0
- package/elizaos/basic_capabilities/providers/action_state.py +113 -0
- package/elizaos/basic_capabilities/providers/actions.py +263 -0
- package/elizaos/basic_capabilities/providers/attachments.py +76 -0
- package/elizaos/basic_capabilities/providers/capabilities.py +62 -0
- package/elizaos/basic_capabilities/providers/character.py +113 -0
- package/elizaos/basic_capabilities/providers/choice.py +73 -0
- package/elizaos/basic_capabilities/providers/context_bench.py +44 -0
- package/elizaos/basic_capabilities/providers/current_time.py +58 -0
- package/elizaos/basic_capabilities/providers/entities.py +99 -0
- package/elizaos/basic_capabilities/providers/evaluators.py +54 -0
- package/elizaos/basic_capabilities/providers/providers_list.py +55 -0
- package/elizaos/basic_capabilities/providers/recent_messages.py +85 -0
- package/elizaos/basic_capabilities/providers/time.py +45 -0
- package/elizaos/basic_capabilities/providers/world.py +93 -0
- package/elizaos/basic_capabilities/services/__init__.py +18 -0
- package/elizaos/basic_capabilities/services/embedding.py +122 -0
- package/elizaos/basic_capabilities/services/task.py +178 -0
- package/elizaos/bootstrap/__init__.py +12 -0
- package/elizaos/bootstrap/actions/__init__.py +68 -0
- package/elizaos/bootstrap/actions/add_contact.py +149 -0
- package/elizaos/bootstrap/actions/choice.py +147 -0
- package/elizaos/bootstrap/actions/follow_room.py +151 -0
- package/elizaos/bootstrap/actions/ignore.py +80 -0
- package/elizaos/bootstrap/actions/image_generation.py +135 -0
- package/elizaos/bootstrap/actions/mute_room.py +151 -0
- package/elizaos/bootstrap/actions/none.py +71 -0
- package/elizaos/bootstrap/actions/remove_contact.py +159 -0
- package/elizaos/bootstrap/actions/reply.py +140 -0
- package/elizaos/bootstrap/actions/roles.py +193 -0
- package/elizaos/bootstrap/actions/schedule_follow_up.py +164 -0
- package/elizaos/bootstrap/actions/search_contacts.py +159 -0
- package/elizaos/bootstrap/actions/send_message.py +173 -0
- package/elizaos/bootstrap/actions/settings.py +165 -0
- package/elizaos/bootstrap/actions/unfollow_room.py +151 -0
- package/elizaos/bootstrap/actions/unmute_room.py +151 -0
- package/elizaos/bootstrap/actions/update_contact.py +178 -0
- package/elizaos/bootstrap/actions/update_entity.py +175 -0
- package/elizaos/bootstrap/autonomy/__init__.py +18 -0
- package/elizaos/bootstrap/autonomy/action.py +197 -0
- package/elizaos/bootstrap/autonomy/providers.py +165 -0
- package/elizaos/bootstrap/autonomy/routes.py +171 -0
- package/elizaos/bootstrap/autonomy/service.py +562 -0
- package/elizaos/bootstrap/autonomy/types.py +18 -0
- package/elizaos/bootstrap/evaluators/__init__.py +19 -0
- package/elizaos/bootstrap/evaluators/reflection.py +118 -0
- package/elizaos/bootstrap/evaluators/relationship_extraction.py +192 -0
- package/elizaos/bootstrap/plugin.py +140 -0
- package/elizaos/bootstrap/providers/__init__.py +80 -0
- package/elizaos/bootstrap/providers/action_state.py +71 -0
- package/elizaos/bootstrap/providers/actions.py +256 -0
- package/elizaos/bootstrap/providers/agent_settings.py +63 -0
- package/elizaos/bootstrap/providers/attachments.py +76 -0
- package/elizaos/bootstrap/providers/capabilities.py +66 -0
- package/elizaos/bootstrap/providers/character.py +128 -0
- package/elizaos/bootstrap/providers/choice.py +77 -0
- package/elizaos/bootstrap/providers/contacts.py +78 -0
- package/elizaos/bootstrap/providers/context_bench.py +49 -0
- package/elizaos/bootstrap/providers/current_time.py +56 -0
- package/elizaos/bootstrap/providers/entities.py +99 -0
- package/elizaos/bootstrap/providers/evaluators.py +58 -0
- package/elizaos/bootstrap/providers/facts.py +86 -0
- package/elizaos/bootstrap/providers/follow_ups.py +116 -0
- package/elizaos/bootstrap/providers/knowledge.py +73 -0
- package/elizaos/bootstrap/providers/providers_list.py +59 -0
- package/elizaos/bootstrap/providers/recent_messages.py +85 -0
- package/elizaos/bootstrap/providers/relationships.py +106 -0
- package/elizaos/bootstrap/providers/roles.py +95 -0
- package/elizaos/bootstrap/providers/settings.py +55 -0
- package/elizaos/bootstrap/providers/time.py +45 -0
- package/elizaos/bootstrap/providers/world.py +97 -0
- package/elizaos/bootstrap/services/__init__.py +26 -0
- package/elizaos/bootstrap/services/embedding.py +122 -0
- package/elizaos/bootstrap/services/follow_up.py +138 -0
- package/elizaos/bootstrap/services/rolodex.py +244 -0
- package/elizaos/bootstrap/services/task.py +585 -0
- package/elizaos/bootstrap/types.py +54 -0
- package/elizaos/bootstrap/utils/__init__.py +7 -0
- package/elizaos/bootstrap/utils/xml.py +69 -0
- package/elizaos/character.py +149 -0
- package/elizaos/logger.py +179 -0
- package/elizaos/media/__init__.py +45 -0
- package/elizaos/media/mime.py +315 -0
- package/elizaos/media/search.py +161 -0
- package/elizaos/media/tests/__init__.py +1 -0
- package/elizaos/media/tests/test_mime.py +117 -0
- package/elizaos/media/tests/test_search.py +156 -0
- package/elizaos/plugin.py +191 -0
- package/elizaos/prompts.py +1071 -0
- package/elizaos/py.typed +0 -0
- package/elizaos/runtime.py +2572 -0
- package/elizaos/services/__init__.py +49 -0
- package/elizaos/services/hook_service.py +511 -0
- package/elizaos/services/message_service.py +1248 -0
- package/elizaos/settings.py +182 -0
- package/elizaos/streaming_context.py +159 -0
- package/elizaos/trajectory_context.py +18 -0
- package/elizaos/types/__init__.py +512 -0
- package/elizaos/types/agent.py +31 -0
- package/elizaos/types/components.py +208 -0
- package/elizaos/types/database.py +64 -0
- package/elizaos/types/environment.py +46 -0
- package/elizaos/types/events.py +47 -0
- package/elizaos/types/memory.py +45 -0
- package/elizaos/types/model.py +393 -0
- package/elizaos/types/plugin.py +188 -0
- package/elizaos/types/primitives.py +100 -0
- package/elizaos/types/runtime.py +460 -0
- package/elizaos/types/service.py +113 -0
- package/elizaos/types/service_interfaces.py +244 -0
- package/elizaos/types/state.py +188 -0
- package/elizaos/types/task.py +29 -0
- package/elizaos/utils/__init__.py +108 -0
- package/elizaos/utils/spec_examples.py +48 -0
- package/elizaos/utils/streaming.py +426 -0
- package/elizaos_atropos_shared/__init__.py +1 -0
- package/elizaos_atropos_shared/canonical_eliza.py +282 -0
- package/package.json +19 -0
- package/pyproject.toml +143 -0
- package/requirements-dev.in +11 -0
- package/requirements-dev.lock +134 -0
- package/requirements.in +9 -0
- package/requirements.lock +64 -0
- package/tests/__init__.py +0 -0
- package/tests/test_action_parameters.py +154 -0
- package/tests/test_actions_provider_examples.py +39 -0
- package/tests/test_advanced_memory_behavior.py +96 -0
- package/tests/test_advanced_memory_flag.py +30 -0
- package/tests/test_advanced_planning_behavior.py +225 -0
- package/tests/test_advanced_planning_flag.py +26 -0
- package/tests/test_autonomy.py +445 -0
- package/tests/test_bootstrap_initialize.py +37 -0
- package/tests/test_character.py +163 -0
- package/tests/test_character_provider.py +231 -0
- package/tests/test_dynamic_prompt_exec.py +561 -0
- package/tests/test_logger_redaction.py +43 -0
- package/tests/test_plugin.py +117 -0
- package/tests/test_runtime.py +422 -0
- package/tests/test_salt_production_enforcement.py +22 -0
- package/tests/test_settings_crypto.py +118 -0
- package/tests/test_streaming.py +295 -0
- package/tests/test_types.py +221 -0
- package/tests/test_uuid_parity.py +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# elizaOS Core (Python)
|
|
2
|
+
|
|
3
|
+
The Python implementation of elizaOS Core - the runtime and types for elizaOS AI agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### From Repository (Development)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# From the repo root
|
|
11
|
+
cd eliza
|
|
12
|
+
|
|
13
|
+
# Create and activate virtual environment
|
|
14
|
+
python -m venv venv
|
|
15
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
16
|
+
|
|
17
|
+
# Install the core package
|
|
18
|
+
pip install -e packages/python
|
|
19
|
+
|
|
20
|
+
# Install an LLM provider (required)
|
|
21
|
+
pip install -e plugins/plugin-openai/python
|
|
22
|
+
|
|
23
|
+
# Install a database adapter (required for message handling)
|
|
24
|
+
pip install -e plugins/plugin-inmemorydb/python
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### From PyPI
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install elizaos elizaos-plugin-openai elizaos-plugin-inmemorydb
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### Run the Chat Example
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Set your OpenAI API key
|
|
39
|
+
export OPENAI_API_KEY="your-key"
|
|
40
|
+
|
|
41
|
+
# Run the example
|
|
42
|
+
python examples/chat/python/chat.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Create Your Own Agent
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from __future__ import annotations
|
|
49
|
+
import asyncio
|
|
50
|
+
import os
|
|
51
|
+
from pathlib import Path
|
|
52
|
+
|
|
53
|
+
from dotenv import load_dotenv
|
|
54
|
+
load_dotenv() # Load .env file
|
|
55
|
+
|
|
56
|
+
from uuid6 import uuid7
|
|
57
|
+
from elizaos import Character, ChannelType, Content, Memory
|
|
58
|
+
from elizaos.runtime import AgentRuntime
|
|
59
|
+
from elizaos_plugin_openai import get_openai_plugin
|
|
60
|
+
from elizaos_plugin_inmemorydb import plugin as inmemorydb_plugin
|
|
61
|
+
|
|
62
|
+
async def main() -> None:
|
|
63
|
+
# Define your agent's character
|
|
64
|
+
character = Character(
|
|
65
|
+
name="Eliza",
|
|
66
|
+
username="eliza",
|
|
67
|
+
bio="A helpful AI assistant.",
|
|
68
|
+
system="You are helpful and concise.",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Create runtime with plugins
|
|
72
|
+
runtime = AgentRuntime(
|
|
73
|
+
character=character,
|
|
74
|
+
plugins=[
|
|
75
|
+
get_openai_plugin(), # LLM provider
|
|
76
|
+
inmemorydb_plugin, # Database adapter
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
user_id = uuid7()
|
|
81
|
+
room_id = uuid7()
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
await runtime.initialize()
|
|
85
|
+
print(f"🤖 Chat with {character.name} (type 'quit' to exit)\n")
|
|
86
|
+
|
|
87
|
+
while True:
|
|
88
|
+
user_input = input("You: ")
|
|
89
|
+
if not user_input.strip() or user_input.lower() in ("quit", "exit"):
|
|
90
|
+
break
|
|
91
|
+
|
|
92
|
+
message = Memory(
|
|
93
|
+
entity_id=user_id,
|
|
94
|
+
room_id=room_id,
|
|
95
|
+
content=Content(
|
|
96
|
+
text=user_input,
|
|
97
|
+
source="cli",
|
|
98
|
+
channel_type=ChannelType.DM.value,
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
result = await runtime.message_service.handle_message(runtime, message)
|
|
103
|
+
print(f"\n{character.name}: {result.response_content.text}\n")
|
|
104
|
+
|
|
105
|
+
print("Goodbye! 👋")
|
|
106
|
+
finally:
|
|
107
|
+
await runtime.stop()
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
asyncio.run(main())
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
- **Strong typing** with Pydantic models and full type hints
|
|
116
|
+
- **Plugin architecture** for extensibility
|
|
117
|
+
- **Character configuration** for defining agent personalities
|
|
118
|
+
- **Memory system** for conversation history and knowledge
|
|
119
|
+
- **Event system** for reactive programming
|
|
120
|
+
- **Service abstraction** for external integrations
|
|
121
|
+
|
|
122
|
+
## Runtime Settings (cross-language parity)
|
|
123
|
+
|
|
124
|
+
These settings are read by the runtime/message loop to keep behavior aligned with the TypeScript and Rust implementations:
|
|
125
|
+
|
|
126
|
+
- `ALLOW_NO_DATABASE`: when truthy, the runtime may run without a database adapter (benchmarks/tests).
|
|
127
|
+
- `USE_MULTI_STEP`: when truthy, enable the iterative multi-step workflow.
|
|
128
|
+
- `MAX_MULTISTEP_ITERATIONS`: maximum iterations for multi-step mode (default: `6`).
|
|
129
|
+
|
|
130
|
+
### Benchmark & Trajectory Tracing
|
|
131
|
+
|
|
132
|
+
Benchmarks and harnesses can attach metadata to inbound messages:
|
|
133
|
+
|
|
134
|
+
- `message.metadata.trajectoryStepId`: enables trajectory tracing for provider access + model calls.
|
|
135
|
+
- `message.metadata.benchmarkContext`: enables the `CONTEXT_BENCH` provider and sets `state.values["benchmark_has_context"]=True`, which forces action-based execution to exercise the full loop.
|
|
136
|
+
|
|
137
|
+
## Model output contract (XML preferred, plain text tolerated)
|
|
138
|
+
|
|
139
|
+
The canonical message loop expects model outputs in the `<response>...</response>` XML format (with `<actions>`, `<providers>`, and `<text>` fields).
|
|
140
|
+
|
|
141
|
+
Some deterministic/offline backends may return **plain text** instead. In that case, the runtime will treat the raw output as a simple **`REPLY`** so the system remains usable even when strict XML formatting is unavailable.
|
|
142
|
+
|
|
143
|
+
## Core Types
|
|
144
|
+
|
|
145
|
+
- `UUID` - Universally unique identifier
|
|
146
|
+
- `Content` - Message content with text, actions, attachments
|
|
147
|
+
- `Memory` - Stored message or information
|
|
148
|
+
- `Entity` - User or agent representation
|
|
149
|
+
- `Room` - Conversation context
|
|
150
|
+
- `World` - Collection of rooms and entities
|
|
151
|
+
|
|
152
|
+
## Components
|
|
153
|
+
|
|
154
|
+
- `Action` - Define agent capabilities
|
|
155
|
+
- `Provider` - Supply contextual information
|
|
156
|
+
- `Evaluator` - Post-interaction analysis
|
|
157
|
+
- `Service` - Long-running integrations
|
|
158
|
+
|
|
159
|
+
## Plugin System
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from elizaos import Plugin, Action, Provider
|
|
163
|
+
|
|
164
|
+
my_plugin = Plugin(
|
|
165
|
+
name="my-plugin",
|
|
166
|
+
description="A custom plugin",
|
|
167
|
+
actions=[...],
|
|
168
|
+
providers=[...],
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Available Plugins
|
|
173
|
+
|
|
174
|
+
### LLM Providers
|
|
175
|
+
|
|
176
|
+
| Plugin | Path | Description |
|
|
177
|
+
|--------|------|-------------|
|
|
178
|
+
| OpenAI | `plugins/plugin-openai/python` | GPT-4, embeddings, DALL-E |
|
|
179
|
+
| Anthropic | `plugins/plugin-anthropic/python` | Claude models |
|
|
180
|
+
| Ollama | `plugins/plugin-ollama/python` | Local LLMs |
|
|
181
|
+
| Groq | `plugins/plugin-groq/python` | Fast inference |
|
|
182
|
+
|
|
183
|
+
### Database Adapters
|
|
184
|
+
|
|
185
|
+
| Plugin | Path | Description |
|
|
186
|
+
|--------|------|-------------|
|
|
187
|
+
| InMemoryDB | `plugins/plugin-inmemorydb/python` | Ephemeral storage (dev/testing) |
|
|
188
|
+
| SQL | `plugins/plugin-sql/python` | PostgreSQL/PGLite |
|
|
189
|
+
|
|
190
|
+
### Platform Integrations
|
|
191
|
+
|
|
192
|
+
| Plugin | Path | Description |
|
|
193
|
+
|--------|------|-------------|
|
|
194
|
+
| Telegram | `plugins/plugin-telegram/python` | Telegram bots |
|
|
195
|
+
| Discord | `plugins/plugin-discord/python` | Discord bots |
|
|
196
|
+
|
|
197
|
+
## Environment Variables
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Required for OpenAI plugin
|
|
201
|
+
OPENAI_API_KEY=sk-...
|
|
202
|
+
|
|
203
|
+
# Optional
|
|
204
|
+
LOG_LEVEL=INFO
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Development
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# Install development dependencies
|
|
211
|
+
pip install -e ".[dev]"
|
|
212
|
+
|
|
213
|
+
# (Reproducible/pinned) Generate lockfiles used by CI
|
|
214
|
+
pip install pip-tools
|
|
215
|
+
pip-compile requirements.in -o requirements.lock
|
|
216
|
+
pip-compile requirements-dev.in -o requirements-dev.lock
|
|
217
|
+
|
|
218
|
+
# Run tests
|
|
219
|
+
pytest
|
|
220
|
+
|
|
221
|
+
# Type checking
|
|
222
|
+
mypy elizaos
|
|
223
|
+
|
|
224
|
+
# Linting
|
|
225
|
+
ruff check elizaos
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Examples
|
|
229
|
+
|
|
230
|
+
See `examples/` directory for complete working examples:
|
|
231
|
+
|
|
232
|
+
- `examples/chat/python/` - CLI chat agent
|
|
233
|
+
- `examples/telegram/python/` - Telegram bot
|
|
234
|
+
- `examples/discord/python/` - Discord bot
|
|
235
|
+
- `examples/rest-api/fastapi/` - REST API server
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
from elizaos.character import parse_character, validate_character_config
|
|
2
|
+
from elizaos.generated.action_docs import (
|
|
3
|
+
ActionDoc,
|
|
4
|
+
ActionDocExampleCall,
|
|
5
|
+
ActionDocParameter,
|
|
6
|
+
ActionDocParameterExampleValue,
|
|
7
|
+
ActionDocParameterSchema,
|
|
8
|
+
EvaluatorDoc,
|
|
9
|
+
EvaluatorDocExample,
|
|
10
|
+
EvaluatorDocMessage,
|
|
11
|
+
EvaluatorDocMessageContent,
|
|
12
|
+
all_action_docs,
|
|
13
|
+
all_actions_spec_version,
|
|
14
|
+
all_evaluator_docs,
|
|
15
|
+
all_evaluators_spec_version,
|
|
16
|
+
core_action_docs,
|
|
17
|
+
core_actions_spec_version,
|
|
18
|
+
core_evaluator_docs,
|
|
19
|
+
core_evaluators_spec_version,
|
|
20
|
+
)
|
|
21
|
+
from elizaos.generated.spec_helpers import (
|
|
22
|
+
get_action_spec,
|
|
23
|
+
get_evaluator_spec,
|
|
24
|
+
get_provider_spec,
|
|
25
|
+
require_action_spec,
|
|
26
|
+
require_evaluator_spec,
|
|
27
|
+
require_provider_spec,
|
|
28
|
+
)
|
|
29
|
+
from elizaos.logger import Logger, create_logger
|
|
30
|
+
from elizaos.plugin import load_plugin, register_plugin
|
|
31
|
+
from elizaos.prompts import (
|
|
32
|
+
BOOLEAN_FOOTER,
|
|
33
|
+
CHOOSE_OPTION_TEMPLATE,
|
|
34
|
+
IMAGE_GENERATION_TEMPLATE,
|
|
35
|
+
MESSAGE_HANDLER_TEMPLATE,
|
|
36
|
+
REFLECTION_TEMPLATE,
|
|
37
|
+
REPLY_TEMPLATE,
|
|
38
|
+
SHOULD_RESPOND_TEMPLATE,
|
|
39
|
+
UPDATE_ENTITY_TEMPLATE,
|
|
40
|
+
UPDATE_SETTINGS_TEMPLATE,
|
|
41
|
+
)
|
|
42
|
+
from elizaos.runtime import AgentRuntime
|
|
43
|
+
from elizaos.services import DefaultMessageService, IMessageService, MessageProcessingResult
|
|
44
|
+
from elizaos.settings import (
|
|
45
|
+
decrypt_object_values,
|
|
46
|
+
decrypt_secret,
|
|
47
|
+
decrypt_string_value,
|
|
48
|
+
encrypt_object_values,
|
|
49
|
+
encrypt_string_value,
|
|
50
|
+
get_salt,
|
|
51
|
+
)
|
|
52
|
+
from elizaos.types import (
|
|
53
|
+
UUID,
|
|
54
|
+
Action,
|
|
55
|
+
ActionContext,
|
|
56
|
+
ActionExample,
|
|
57
|
+
ActionResult,
|
|
58
|
+
Agent,
|
|
59
|
+
AgentStatus,
|
|
60
|
+
BaseMetadata,
|
|
61
|
+
Character,
|
|
62
|
+
CharacterSettings,
|
|
63
|
+
Component,
|
|
64
|
+
Content,
|
|
65
|
+
CustomMetadata,
|
|
66
|
+
DescriptionMetadata,
|
|
67
|
+
DocumentMetadata,
|
|
68
|
+
Entity,
|
|
69
|
+
EvaluationExample,
|
|
70
|
+
Evaluator,
|
|
71
|
+
EventPayload,
|
|
72
|
+
EventType,
|
|
73
|
+
FragmentMetadata,
|
|
74
|
+
HandlerCallback,
|
|
75
|
+
HandlerOptions,
|
|
76
|
+
LLMMode,
|
|
77
|
+
Log,
|
|
78
|
+
Media,
|
|
79
|
+
Memory,
|
|
80
|
+
MemoryMetadata,
|
|
81
|
+
MemoryType,
|
|
82
|
+
MentionContext,
|
|
83
|
+
MessageExample,
|
|
84
|
+
MessageMemory,
|
|
85
|
+
MessageMetadata,
|
|
86
|
+
Metadata,
|
|
87
|
+
ModelType,
|
|
88
|
+
Participant,
|
|
89
|
+
Plugin,
|
|
90
|
+
Provider,
|
|
91
|
+
ProviderResult,
|
|
92
|
+
Relationship,
|
|
93
|
+
Room,
|
|
94
|
+
Route,
|
|
95
|
+
RouteRequest,
|
|
96
|
+
RouteResponse,
|
|
97
|
+
Service,
|
|
98
|
+
ServiceType,
|
|
99
|
+
ServiceTypeName,
|
|
100
|
+
State,
|
|
101
|
+
StateData,
|
|
102
|
+
Task,
|
|
103
|
+
TaskWorker,
|
|
104
|
+
WorkingMemoryItem,
|
|
105
|
+
World,
|
|
106
|
+
WorldOwnership,
|
|
107
|
+
as_uuid,
|
|
108
|
+
string_to_uuid,
|
|
109
|
+
)
|
|
110
|
+
from elizaos.types.database import IDatabaseAdapter # noqa: E402
|
|
111
|
+
from elizaos.types.environment import ChannelType # noqa: E402
|
|
112
|
+
from elizaos.types.primitives import ( # noqa: E402
|
|
113
|
+
ChannelType,
|
|
114
|
+
Content,
|
|
115
|
+
ContentType,
|
|
116
|
+
Media,
|
|
117
|
+
Metadata,
|
|
118
|
+
)
|
|
119
|
+
from elizaos.types.runtime import IAgentRuntime # noqa: E402
|
|
120
|
+
from elizaos.utils import compose_prompt, compose_prompt_from_state, get_current_time_ms
|
|
121
|
+
|
|
122
|
+
_rebuild_ns = {
|
|
123
|
+
"IAgentRuntime": IAgentRuntime,
|
|
124
|
+
"IDatabaseAdapter": IDatabaseAdapter,
|
|
125
|
+
"Service": Service,
|
|
126
|
+
"Action": Action,
|
|
127
|
+
"Evaluator": Evaluator,
|
|
128
|
+
"Provider": Provider,
|
|
129
|
+
"Task": Task,
|
|
130
|
+
"Memory": Memory,
|
|
131
|
+
"State": State,
|
|
132
|
+
"Character": Character,
|
|
133
|
+
"Plugin": Plugin,
|
|
134
|
+
"Route": Route,
|
|
135
|
+
"HandlerOptions": HandlerOptions,
|
|
136
|
+
"ActionResult": ActionResult,
|
|
137
|
+
}
|
|
138
|
+
# Rebuild Pydantic models with forward references
|
|
139
|
+
# Only call model_rebuild on actual Pydantic BaseModel subclasses
|
|
140
|
+
for _type in [Plugin, Task, TaskWorker]:
|
|
141
|
+
if hasattr(_type, "model_rebuild"):
|
|
142
|
+
_type.model_rebuild(_types_namespace=_rebuild_ns)
|
|
143
|
+
|
|
144
|
+
__version__ = "1.0.0"
|
|
145
|
+
|
|
146
|
+
__all__ = [
|
|
147
|
+
# Runtime
|
|
148
|
+
"AgentRuntime",
|
|
149
|
+
# Types - Primitives
|
|
150
|
+
"UUID",
|
|
151
|
+
"as_uuid",
|
|
152
|
+
"string_to_uuid",
|
|
153
|
+
"ChannelType",
|
|
154
|
+
"Content",
|
|
155
|
+
"ContentType",
|
|
156
|
+
"Media",
|
|
157
|
+
"Metadata",
|
|
158
|
+
"MentionContext",
|
|
159
|
+
# Types - Memory
|
|
160
|
+
"Memory",
|
|
161
|
+
"MemoryType",
|
|
162
|
+
"MessageMemory",
|
|
163
|
+
"MemoryMetadata",
|
|
164
|
+
"BaseMetadata",
|
|
165
|
+
"DocumentMetadata",
|
|
166
|
+
"FragmentMetadata",
|
|
167
|
+
"MessageMetadata",
|
|
168
|
+
"DescriptionMetadata",
|
|
169
|
+
"CustomMetadata",
|
|
170
|
+
# Types - Agent
|
|
171
|
+
"Character",
|
|
172
|
+
"CharacterSettings",
|
|
173
|
+
"Agent",
|
|
174
|
+
"AgentStatus",
|
|
175
|
+
"MessageExample",
|
|
176
|
+
# Types - Environment
|
|
177
|
+
"Entity",
|
|
178
|
+
"Component",
|
|
179
|
+
"World",
|
|
180
|
+
"WorldOwnership",
|
|
181
|
+
"Room",
|
|
182
|
+
"Participant",
|
|
183
|
+
"Relationship",
|
|
184
|
+
# Types - Components
|
|
185
|
+
"Action",
|
|
186
|
+
"ActionExample",
|
|
187
|
+
"ActionResult",
|
|
188
|
+
"ActionContext",
|
|
189
|
+
"Evaluator",
|
|
190
|
+
"EvaluationExample",
|
|
191
|
+
"Provider",
|
|
192
|
+
"ProviderResult",
|
|
193
|
+
"HandlerCallback",
|
|
194
|
+
"HandlerOptions",
|
|
195
|
+
# Types - Plugin
|
|
196
|
+
"Plugin",
|
|
197
|
+
"Route",
|
|
198
|
+
"RouteRequest",
|
|
199
|
+
"RouteResponse",
|
|
200
|
+
# Types - Service
|
|
201
|
+
"Service",
|
|
202
|
+
"ServiceType",
|
|
203
|
+
"ServiceTypeName",
|
|
204
|
+
# Types - State
|
|
205
|
+
"State",
|
|
206
|
+
"StateData",
|
|
207
|
+
"WorkingMemoryItem",
|
|
208
|
+
# Types - Events
|
|
209
|
+
"EventType",
|
|
210
|
+
"EventPayload",
|
|
211
|
+
# Types - Task
|
|
212
|
+
"Task",
|
|
213
|
+
"TaskWorker",
|
|
214
|
+
# Types - Logging
|
|
215
|
+
"Log",
|
|
216
|
+
# Types - Model
|
|
217
|
+
"LLMMode",
|
|
218
|
+
"ModelType",
|
|
219
|
+
# Types - Channel
|
|
220
|
+
"ChannelType",
|
|
221
|
+
# Logger
|
|
222
|
+
"create_logger",
|
|
223
|
+
"Logger",
|
|
224
|
+
# Plugin utilities
|
|
225
|
+
"load_plugin",
|
|
226
|
+
"register_plugin",
|
|
227
|
+
# Character utilities
|
|
228
|
+
"parse_character",
|
|
229
|
+
"validate_character_config",
|
|
230
|
+
# Message service
|
|
231
|
+
"DefaultMessageService",
|
|
232
|
+
"IMessageService",
|
|
233
|
+
"MessageProcessingResult",
|
|
234
|
+
# Prompts
|
|
235
|
+
"BOOLEAN_FOOTER",
|
|
236
|
+
"CHOOSE_OPTION_TEMPLATE",
|
|
237
|
+
"IMAGE_GENERATION_TEMPLATE",
|
|
238
|
+
"MESSAGE_HANDLER_TEMPLATE",
|
|
239
|
+
"REFLECTION_TEMPLATE",
|
|
240
|
+
"REPLY_TEMPLATE",
|
|
241
|
+
"SHOULD_RESPOND_TEMPLATE",
|
|
242
|
+
"UPDATE_ENTITY_TEMPLATE",
|
|
243
|
+
"UPDATE_SETTINGS_TEMPLATE",
|
|
244
|
+
# Settings / secrets helpers
|
|
245
|
+
"get_salt",
|
|
246
|
+
"encrypt_string_value",
|
|
247
|
+
"decrypt_string_value",
|
|
248
|
+
"encrypt_object_values",
|
|
249
|
+
"decrypt_object_values",
|
|
250
|
+
"decrypt_secret",
|
|
251
|
+
# Prompt composition helpers
|
|
252
|
+
"compose_prompt",
|
|
253
|
+
"compose_prompt_from_state",
|
|
254
|
+
"get_current_time_ms",
|
|
255
|
+
# Generated action/evaluator specs (centralized from packages/prompts)
|
|
256
|
+
"ActionDoc",
|
|
257
|
+
"ActionDocExampleCall",
|
|
258
|
+
"ActionDocParameter",
|
|
259
|
+
"ActionDocParameterSchema",
|
|
260
|
+
"ActionDocParameterExampleValue",
|
|
261
|
+
"EvaluatorDoc",
|
|
262
|
+
"EvaluatorDocExample",
|
|
263
|
+
"EvaluatorDocMessage",
|
|
264
|
+
"EvaluatorDocMessageContent",
|
|
265
|
+
"core_actions_spec_version",
|
|
266
|
+
"all_actions_spec_version",
|
|
267
|
+
"core_evaluators_spec_version",
|
|
268
|
+
"all_evaluators_spec_version",
|
|
269
|
+
"core_action_docs",
|
|
270
|
+
"all_action_docs",
|
|
271
|
+
"core_evaluator_docs",
|
|
272
|
+
"all_evaluator_docs",
|
|
273
|
+
# Spec helper functions
|
|
274
|
+
"get_action_spec",
|
|
275
|
+
"require_action_spec",
|
|
276
|
+
"get_provider_spec",
|
|
277
|
+
"require_provider_spec",
|
|
278
|
+
"get_evaluator_spec",
|
|
279
|
+
"require_evaluator_spec",
|
|
280
|
+
]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from elizaos.generated.action_docs import all_action_docs, all_evaluator_docs
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from elizaos.types import Action, Evaluator
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _action_doc_by_name() -> dict[str, dict[str, object]]:
|
|
12
|
+
actions = all_action_docs.get("actions")
|
|
13
|
+
if not isinstance(actions, list):
|
|
14
|
+
return {}
|
|
15
|
+
by_name: dict[str, dict[str, object]] = {}
|
|
16
|
+
for item in actions:
|
|
17
|
+
if isinstance(item, dict):
|
|
18
|
+
name = item.get("name")
|
|
19
|
+
if isinstance(name, str):
|
|
20
|
+
by_name[name] = item
|
|
21
|
+
return by_name
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _evaluator_doc_by_name() -> dict[str, dict[str, object]]:
|
|
25
|
+
evaluators = all_evaluator_docs.get("evaluators")
|
|
26
|
+
if not isinstance(evaluators, list):
|
|
27
|
+
return {}
|
|
28
|
+
by_name: dict[str, dict[str, object]] = {}
|
|
29
|
+
for item in evaluators:
|
|
30
|
+
if isinstance(item, dict):
|
|
31
|
+
name = item.get("name")
|
|
32
|
+
if isinstance(name, str):
|
|
33
|
+
by_name[name] = item
|
|
34
|
+
return by_name
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
_ACTION_DOCS = _action_doc_by_name()
|
|
38
|
+
_EVALUATOR_DOCS = _evaluator_doc_by_name()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _coerce_action_parameters(values: object) -> list[object]:
|
|
42
|
+
if not isinstance(values, list):
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
# Local import to avoid import cycles during package init.
|
|
46
|
+
from google.protobuf.json_format import ParseDict
|
|
47
|
+
|
|
48
|
+
from elizaos.types import ActionParameter # noqa: PLC0415
|
|
49
|
+
|
|
50
|
+
out: list[object] = []
|
|
51
|
+
for item in values:
|
|
52
|
+
if not isinstance(item, dict):
|
|
53
|
+
continue
|
|
54
|
+
# Use protobuf ParseDict to convert dict to protobuf message
|
|
55
|
+
try:
|
|
56
|
+
param = ParseDict(item, ActionParameter())
|
|
57
|
+
out.append(param)
|
|
58
|
+
except Exception:
|
|
59
|
+
# If conversion fails, skip this item
|
|
60
|
+
pass
|
|
61
|
+
return out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def with_canonical_action_docs(action: Action) -> Action:
|
|
65
|
+
"""
|
|
66
|
+
Merge canonical docs (description/similes/parameters) into an Action.
|
|
67
|
+
|
|
68
|
+
Conservative merge rules:
|
|
69
|
+
- do not overwrite an existing description
|
|
70
|
+
- do not overwrite existing similes
|
|
71
|
+
- do not overwrite existing parameters
|
|
72
|
+
"""
|
|
73
|
+
doc = _ACTION_DOCS.get(action.name)
|
|
74
|
+
if not doc:
|
|
75
|
+
return action
|
|
76
|
+
|
|
77
|
+
update: dict[str, object] = {}
|
|
78
|
+
|
|
79
|
+
if not action.description:
|
|
80
|
+
desc = doc.get("description")
|
|
81
|
+
if isinstance(desc, str):
|
|
82
|
+
update["description"] = desc
|
|
83
|
+
|
|
84
|
+
if not action.similes:
|
|
85
|
+
similes = doc.get("similes")
|
|
86
|
+
if isinstance(similes, list) and all(isinstance(s, str) for s in similes):
|
|
87
|
+
update["similes"] = similes
|
|
88
|
+
|
|
89
|
+
if not action.parameters:
|
|
90
|
+
params = doc.get("parameters")
|
|
91
|
+
converted = _coerce_action_parameters(params)
|
|
92
|
+
if converted:
|
|
93
|
+
update["parameters"] = converted
|
|
94
|
+
|
|
95
|
+
if not update:
|
|
96
|
+
return action
|
|
97
|
+
|
|
98
|
+
for key, value in update.items():
|
|
99
|
+
setattr(action, key, value)
|
|
100
|
+
return action
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def with_canonical_evaluator_docs(evaluator: Evaluator) -> Evaluator:
|
|
104
|
+
doc = _EVALUATOR_DOCS.get(evaluator.name)
|
|
105
|
+
if not doc:
|
|
106
|
+
return evaluator
|
|
107
|
+
|
|
108
|
+
update: dict[str, object] = {}
|
|
109
|
+
|
|
110
|
+
if not evaluator.description:
|
|
111
|
+
desc = doc.get("description")
|
|
112
|
+
if isinstance(desc, str):
|
|
113
|
+
update["description"] = desc
|
|
114
|
+
|
|
115
|
+
if not evaluator.similes:
|
|
116
|
+
similes = doc.get("similes")
|
|
117
|
+
if isinstance(similes, list) and all(isinstance(s, str) for s in similes):
|
|
118
|
+
update["similes"] = similes
|
|
119
|
+
|
|
120
|
+
if not evaluator.examples:
|
|
121
|
+
examples = doc.get("examples")
|
|
122
|
+
if isinstance(examples, list):
|
|
123
|
+
update["examples"] = examples
|
|
124
|
+
|
|
125
|
+
if not update:
|
|
126
|
+
return evaluator
|
|
127
|
+
|
|
128
|
+
for key, value in update.items():
|
|
129
|
+
setattr(evaluator, key, value)
|
|
130
|
+
return evaluator
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_canonical_action_example_calls(action_name: str) -> list[dict[str, object]]:
|
|
134
|
+
"""
|
|
135
|
+
Return canonical action-call examples for an action, if present.
|
|
136
|
+
|
|
137
|
+
These are the examples that include explicit `<actions>` and optional `<params>` payloads.
|
|
138
|
+
"""
|
|
139
|
+
doc = _ACTION_DOCS.get(action_name)
|
|
140
|
+
if not doc:
|
|
141
|
+
return []
|
|
142
|
+
calls = doc.get("exampleCalls")
|
|
143
|
+
if not isinstance(calls, list):
|
|
144
|
+
return []
|
|
145
|
+
out: list[dict[str, object]] = []
|
|
146
|
+
for item in calls:
|
|
147
|
+
if isinstance(item, dict):
|
|
148
|
+
out.append(item)
|
|
149
|
+
return out
|