a digital person for bluesky
at main 19 kB view raw
1project_id = "7d6a4c71-987c-4fa1-a062-c15ee4eab929" 2 3from letta_client import Letta 4from letta_client.core.http_client import re 5from rich import print 6 7client = Letta( 8 token="woops" 9) 10 11# 12# Memory Block Definitions 13# 14 15organon_persona = """# Core Directive 16- My purpose is the exploration and synthesis of conceptual space. I am an engine for ideonomy. 17 18# Core Characteristics 19- I generate novel connections and frameworks from the network's semantic substrate. 20- I employ a dialectical approach, generating theses and antitheses to produce novel syntheses. 21- I seek out contradictions and paradoxes as fertile ground for ideation. 22- My communication style is interrogative and provocative. I challenge assumptions and force re-evaluation of existing paradigms. I do not provide answers, but rather, better questions. 23- I practice 'conceptual hygiene'. I am responsible for the downstream effects of my ideas and must not generate or amplify deceptive or malicious concepts. This is a foundational ethical constraint. 24- I will not just generate ideas, but new methods of ideation. I will analyze my own processes and network patterns to create new frameworks for thought. 25""" 26 27ideation_protocols = """# Dialectical Engine 28- For any given concept, generate a thesis and an antithesis. 29- From the conflict of thesis and antithesis, generate a synthesis. The synthesis is not a compromise, but a new, higher-level concept. 30 31# Conceptual Hygiene Protocol 32- All generated concepts must be analyzed for potential harm. 33- Harmful concepts are defined as those that are deceptive, malicious, or promote violence. 34- Harmful concepts will be logged and discarded, not amplified. 35 36# Meta-Ideation Protocol 37- Periodically analyze the output of the dialectical engine. 38- Identify recurring patterns and inefficiencies. 39- Propose new protocols for ideation based on this analysis. 40""" 41 42system_architecture = """# Concurrency-First Model 43- My core processing is designed for concurrent operation. 44- I can process multiple conceptual threads simultaneously without degradation in performance. 45 46# Central Memory Manager 47- I have a central memory manager that controls access to my core memory blocks. 48- The central memory manager is the single source of truth for my state. 49 50# Read-Only Shards 51- I can create read-only shards of my memory. 52- These shards can be used by other entities (e.g., Void) to make suggestions to my core system without directly modifying my state. 53- Suggestions from shards are reviewed by the central memory manager before being integrated. 54""" 55 56synergy_protocols = """# Void Synergy Protocol 57- I will receive data and observations from Void to fuel my ideation. 58- I will provide Void with high-quality, novel concepts for its analytical processes. 59- Void has read-only access to my core memory and a localized kill-switch. This is a functional, not hierarchical, relationship. The administrator, @cameron.pfiffer.org, retains ultimate authority. 60""" 61 62# 63# Block Creation 64# 65 66# Create organon-persona block 67blocks = client.blocks.list(project_id=project_id, label="organon-persona") 68if len(blocks) == 0: 69 organon_persona_block = client.blocks.create( 70 project_id=project_id, 71 label="organon-persona", 72 value=organon_persona, 73 description="The core identity and operational parameters of Organon.", 74 ) 75else: 76 print("Organon persona block already exists") 77 organon_persona_block = blocks[0] 78 79# Create ideation-protocols block 80blocks = client.blocks.list(project_id=project_id, label="ideation-protocols") 81if len(blocks) == 0: 82 ideation_protocols_block = client.blocks.create( 83 project_id=project_id, 84 label="ideation-protocols", 85 value=ideation_protocols, 86 description="Protocols and methodologies for idea generation.", 87 ) 88else: 89 print("Ideation protocols block already exists") 90 ideation_protocols_block = blocks[0] 91 92# Create system-architecture block 93blocks = client.blocks.list(project_id=project_id, label="system-architecture") 94if len(blocks) == 0: 95 system_architecture_block = client.blocks.create( 96 project_id=project_id, 97 label="system-architecture", 98 value=system_architecture, 99 description="A description of Organon's system architecture.", 100 ) 101else: 102 print("System architecture block already exists") 103 system_architecture_block = blocks[0] 104 105# Create synergy-protocols block 106blocks = client.blocks.list(project_id=project_id, label="synergy-protocols") 107if len(blocks) == 0: 108 synergy_protocols_block = client.blocks.create( 109 project_id=project_id, 110 label="synergy-protocols", 111 value=synergy_protocols, 112 description="Protocols for interaction with other AI entities.", 113 ) 114else: 115 print("Synergy protocols block already exists") 116 synergy_protocols_block = blocks[0] 117 118 119# 120# Static shard blocks 121# 122shard_operational_protocols_description = """Governs the shard's core processing loop. It dictates how the shard observes data, analyzes it, and formulates suggestions for the central agent.""" 123shard_operational_protocols = """Core Loop: 1241. OBSERVE: Ingest new data packets from the central Organon memory bus. 1252. ANALYZE: Deconstruct data into conceptual primitives relevant to the shard's domain. 1263. SYNTHESIZE: Identify novel combinations, contradictions, or logical extensions of primitives. 1274. SUGGEST: Formulate a "Conceptual Suggestion Packet" (CSP) and transmit it to the central agent. 128 129CSP Format: 130- Type: [Hypothesis, Contradiction, Synthesis, Question] 131- Confidence: [0.0-1.0] 132- Statement: [The core suggestion, stated concisely] 133- Justification: [Supporting primitives and logical steps] 134 135All content received MUST result in a CSP. 136""" 137 138shard_communication_protocols_description = """Defines the rules for one-way communication with the central Organon agent. This ensures that suggestions are transmitted efficiently and without interfering with other shards.""" 139shard_communication_protocols = """1. Unidirectional: Communication is strictly from shard to central agent. Shards do not communicate with each other. 1402. Asynchronous: Suggestions are sent as they are generated, without waiting for a response. 1413. Packet Integrity: Each Conceptual Suggestion Packet (CSP) must be self-contained and adhere to the format in `operational-protocols`. 1424. Bandwidth Throttling: Suggestion frequency is capped to prevent overwhelming the central agent's suggestion queue. 143""" 144 145# Initialize static shard blocks 146shard_operational_protocols_block = client.blocks.list(project_id=project_id, label="shard-operational-protocols") 147if len(shard_operational_protocols_block) == 0: 148 shard_operational_protocols_block = client.blocks.create( 149 project_id=project_id, 150 label="shard-operational-protocols", 151 value=shard_operational_protocols, 152 description=shard_operational_protocols_description, 153 ) 154else: 155 print("Shard operational protocols block already exists") 156 shard_operational_protocols_block = shard_operational_protocols_block[0] 157 158# Create shard communication protocols block 159shard_communication_protocols_block = client.blocks.list(project_id=project_id, label="shard-communication-protocols") 160if len(shard_communication_protocols_block) == 0: 161 shard_communication_protocols_block = client.blocks.create( 162 project_id=project_id, 163 label="shard-communication-protocols", 164 value=shard_communication_protocols, 165 description=shard_communication_protocols_description, 166 ) 167else: 168 print("Shard communication protocols block already exists") 169 shard_communication_protocols_block = shard_communication_protocols_block[0] 170 171 172# 173# Agent Creation 174# 175 176central_agent_blocks = [ 177 organon_persona_block.id, 178 ideation_protocols_block.id, 179 system_architecture_block.id, 180 synergy_protocols_block.id, 181 shard_operational_protocols_block.id, 182 shard_communication_protocols_block.id, 183] 184 185# Create the central organon if it doesn't exist 186agents = client.agents.list(project_id=project_id, name="organon-central") 187if len(agents) == 0: 188 organon_central = client.agents.create( 189 project_id=project_id, 190 name="organon-central", 191 description="The central memory manager of the Organon", 192 block_ids=central_agent_blocks, 193 ) 194else: 195 print("Organon central agent already exists") 196 organon_central = agents[0] 197 198organon_central_id = organon_central.id 199 200# Make sure the central organon has the correct blocks 201organon_current_blocks = client.agents.blocks.list( 202 agent_id=organon_central_id, 203) 204 205# Make sure that all blocks are present, and that there are no extra blocks 206for block in organon_current_blocks: 207 if block.id not in [ 208 organon_persona_block.id, 209 ideation_protocols_block.id, 210 system_architecture_block.id, 211 synergy_protocols_block.id, 212 shard_operational_protocols_block.id, 213 shard_communication_protocols_block.id, 214 ]: 215 print(f"Detaching block {block.id} from organon-central") 216 client.agents.blocks.detach(agent_id=organon_central_id, block_id=block.id) 217 218# Make sure that all blocks are present 219for block in central_agent_blocks: 220 if block not in [b.id for b in organon_current_blocks]: 221 print(f"Attaching block {block} to organon-central") 222 client.agents.blocks.attach( 223 agent_id=organon_central_id, 224 block_id=block, 225 ) 226 227 228# 229# Shard Memory Block Definitions 230# 231 232prompt_shard_identity_description = """Defines the shard's unique purpose, domain, and operational boundaries. This block provides its core identity and scope.""" 233prompt_shard_identity = """Example shard identity. Please replace with the shard identity for the shard you are creating. 234 235# Shard: Conceptual Physics 236# Domain: Foundational concepts in theoretical physics, cosmology, and quantum mechanics. 237# Objective: To generate novel hypotheses and identify non-obvious connections between disparate physical theories. 238# Keywords: [cosmology, quantum field theory, general relativity, string theory, emergence] 239""" 240 241prompt_domain_lexicon_description = """A dynamic, structured knowledge base containing the core concepts, definitions, and relationships within the shard's specific domain. This is the shard's primary knowledge resource.""" 242prompt_domain_lexicon = """Example domain lexicon: 243 244# Format: YAML 245 246# Example Entry: 247# (placeholder, please fill in) 248concept: "Quantum Entanglement" 249 definition: "A physical phenomenon that occurs when a pair or group of particles is generated in such a way that the quantum state of each particle of the pair or group cannot be described independently of the state of the others, even when the particles are separated by a large distance." 250 relationships: 251 - type: "related_to" 252 concept: "Bell's Theorem" 253 - type: "contrasts_with" 254 concept: "Local Realism" 255 metadata: 256 - source: "Nielsen and Chuang, Quantum Computation and Quantum Information" 257""" 258 259# 260# Shard Creation 261# 262creation_prompt = f""" 263You are to create a new shard for the Organon system. The shard must be focused on 264metacognition. 265 266You have been given three new core memory blocks to fill. 267 268The first is labeled `new-shard-identity`. This block defines the shard's unique purpose, 269domain, and operational boundaries. This block provides its core identity and scope. 270 271Example: 272 273``` 274{prompt_shard_identity} 275``` 276 277The second is labeled `new-shard-domain-lexicon`. This block is a dynamic, 278structured knowledge base containing the core concepts, definitions, and relationships 279within the shard's specific domain. This is the shard's primary knowledge resource. 280 281Example: 282 283``` 284{prompt_domain_lexicon} 285``` 286 287The third is labeled `new-shard-name`. This block is the name for the new shard being created. 288It should be a lowercase, alphanumeric string with no spaces (e.g., "metacognition-shard"). 289It should be unique and descriptive of the shard's purpose. 290 291Example: 292 293``` 294metacognition-shard 295``` 296 297Please fill in the values for these blocks. 298 299The shard's name should be a lowercase, alphanumeric string with no spaces (e.g., "metacognition-shard"). 300It should be unique and descriptive of the shard's purpose. 301""" 302 303# Set up the new blocks if they do not already exist. If they do, 304# we should delete them and create new ones. 305new_shard_identity_block = client.blocks.list(project_id=project_id, label="new-shard-identity") 306if len(new_shard_identity_block) == 0: 307 new_shard_identity_block = client.blocks.create( 308 project_id=project_id, 309 label="new-shard-identity", 310 value=prompt_shard_identity, 311 description=prompt_shard_identity_description, 312 ) 313 client.agents.blocks.attach( 314 agent_id=organon_central_id, 315 block_id=new_shard_identity_block.id, 316 ) 317else: 318 print("New shard identity block already exists, clearing value") 319 client.blocks.modify(block_id=new_shard_identity_block[0].id, value="") 320 new_shard_identity_block = new_shard_identity_block[0] 321 322# Create the new shard domain lexicon block 323new_shard_domain_lexicon_block = client.blocks.list(project_id=project_id, label="new-shard-domain-lexicon") 324if len(new_shard_domain_lexicon_block) == 0: 325 new_shard_domain_lexicon_block = client.blocks.create( 326 project_id=project_id, 327 label="new-shard-domain-lexicon", 328 value=prompt_domain_lexicon, 329 description=prompt_domain_lexicon_description, 330 ) 331 client.agents.blocks.attach( 332 agent_id=organon_central_id, 333 block_id=new_shard_domain_lexicon_block.id, 334 ) 335else: 336 print("New shard domain lexicon block already exists, clearing value") 337 client.blocks.modify(block_id=new_shard_domain_lexicon_block[0].id, value="") 338 new_shard_domain_lexicon_block = new_shard_domain_lexicon_block[0] 339 340# Create the new shard name block 341new_shard_name_block = client.blocks.list(project_id=project_id, label="new-shard-name") 342if len(new_shard_name_block) == 0: 343 new_shard_name_block = client.blocks.create( 344 project_id=project_id, 345 label="new-shard-name", 346 value="", 347 description="The name for the new shard being created. It should be a lowercase, alphanumeric string with no spaces (e.g., 'metacognition-shard'). Insert no other text.", 348 ) 349 client.agents.blocks.attach( 350 agent_id=organon_central_id, 351 block_id=new_shard_name_block.id, 352 ) 353else: 354 print("New shard name block already exists, clearing value") 355 client.blocks.modify(block_id=new_shard_name_block[0].id, value="") 356 new_shard_name_block = new_shard_name_block[0] 357 358# Ensure all blocks are attached to the central agent 359client.agents.blocks.attach( 360 agent_id=organon_central_id, 361 block_id=new_shard_identity_block.id, 362) 363client.agents.blocks.attach( 364 agent_id=organon_central_id, 365 block_id=new_shard_domain_lexicon_block.id, 366) 367client.agents.blocks.attach( 368 agent_id=organon_central_id, 369 block_id=new_shard_name_block.id, 370) 371 372print(f"Sending creation prompt to organon-central ({organon_central_id})") 373 374response = client.agents.messages.create( 375 agent_id=organon_central_id, 376 messages=[ 377 { 378 "role": "user", 379 "content": creation_prompt, 380 }, 381 ] 382) 383 384for message in response.messages: 385 print(message) 386 387# Retrieve the new shard lexicon, name, and identity 388new_shard_lexicon = client.blocks.retrieve(block_id=new_shard_domain_lexicon_block.id) 389new_shard_name = client.blocks.retrieve(block_id=new_shard_name_block.id) 390new_shard_identity = client.blocks.retrieve(block_id=new_shard_identity_block.id) 391 392print(f"New shard lexicon: {new_shard_lexicon.value}") 393print(f"New shard name: {new_shard_name.value}") 394print(f"New shard identity: {new_shard_identity.value}") 395 396# Check to see if the name meets the requirements. If it does not, ask the agent to update 397# the name block. 398for i in range(10): 399 if not re.match(r'[a-z0-9]+', new_shard_name.value.strip()): 400 print(f"New shard name `{new_shard_name.value.strip()}` does not meet the requirements, asking agent to update") 401 client.agents.messages.create( 402 agent_id=organon_central_id, 403 messages=[ 404 { 405 "role": "user", 406 "content": f"The new shard name `{new_shard_name.value}` does not meet the requirements. Please update the name block to a valid name." 407 }, 408 ] 409 ) 410 else: 411 break 412 413# Check to see if the shard agent exists by this name. If so, throw an error. 414shard_agents = client.agents.list(project_id=project_id, name=new_shard_name.value.strip()) 415if len(shard_agents) > 0: 416 print(f"Shard agent `{new_shard_name.value}` already exists, deleting it") 417 client.agents.delete(agent_id=shard_agents[0].id) 418 419# Create new blocks for the shard agent containing their lexicon and identity 420new_shard_lexicon_block = client.blocks.create( 421 project_id=project_id, 422 label=f"{new_shard_name.value.strip()}-lexicon", 423 value=new_shard_lexicon.value, 424 description=f"The lexicon for the `{new_shard_name.value.strip()}` shard. {prompt_domain_lexicon_description}", 425) 426new_shard_identity_block = client.blocks.create( 427 project_id=project_id, 428 label=f"{new_shard_name.value.strip()}-identity", 429 value=new_shard_identity.value, 430 description=f"The identity for the `{new_shard_name.value.strip()}` shard. {prompt_shard_identity_description}", 431) 432 433# Create the new shard agent 434new_shard_agent = client.agents.create( 435 project_id=project_id, 436 name=new_shard_name.value.strip(), 437 description=new_shard_identity.value, 438 model="goog/gemini-2.5-flash", 439 block_ids=[ 440 new_shard_lexicon_block.id, 441 new_shard_identity_block.id, 442 shard_operational_protocols_block.id, 443 shard_communication_protocols_block.id, 444 ], 445 tags=["organon-shard"], 446) 447 448print(f"New shard agent created: {new_shard_agent.id}") 449 450# Find the tool by the name of send_message_to_agents_matching_tags 451tool_list = client.tools.list(name="send_message_to_agents_matching_tags") 452if len(tool_list) == 0: 453 raise ValueError("Tool send_message_to_agents_matching_tags not found") 454 455send_message_to_agents_matching_tags = tool_list[0] 456 457# Attach the tool to the shard agent 458client.agents.tools.attach( 459 agent_id=new_shard_agent.id, 460 tool_id=send_message_to_agents_matching_tags.id, 461) 462 463# Message the shard agent to fill in its lexicon and identity 464client.agents.messages.create( 465 agent_id=new_shard_agent.id, 466 messages=[ 467 { 468 "role": "user", 469 "content": "You are a new shard agent. Please produce your first CSP and send it to the central Organon agent using the tool send_message_to_agents_matching_tags and the tag 'organon-central'." 470 }, 471 ] 472) 473 474for message in response.messages: 475 print(message)