|
1 | | -# hippodid-python |
| 1 | +# hippodid |
| 2 | + |
| 3 | +Python SDK for [HippoDid](https://hippodid.com) -- character memory for AI agents. |
| 4 | + |
| 5 | +HippoDid gives your AI agents persistent identity: personality, background, rules, structured memories, and agent configuration. This SDK wraps the REST API and adds client-side context assembly for any LLM framework. |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install hippodid |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```python |
| 14 | +from hippodid import HippoDid |
| 15 | + |
| 16 | +hd = HippoDid(api_key="hd_your_key") |
| 17 | + |
| 18 | +# Create a character |
| 19 | +char = hd.create_character(name="Ada", description="Senior engineer") |
| 20 | + |
| 21 | +# Set up her profile |
| 22 | +hd.update_profile( |
| 23 | + char.id, |
| 24 | + system_prompt="You are Ada, a senior software engineer.", |
| 25 | + personality="Analytical, thorough, loves clean architecture", |
| 26 | + rules=["Always suggest tests", "Prefer functional patterns"], |
| 27 | +) |
| 28 | + |
| 29 | +# Add memories |
| 30 | +hd.add_memory(char.id, "Ada led the migration from REST to GraphQL in Q3") |
| 31 | +hd.add_memory(char.id, "Ada prefers Rust for systems work, Python for scripting") |
| 32 | + |
| 33 | +# Search memories |
| 34 | +results = hd.search_memories(char.id, "programming languages") |
| 35 | +``` |
| 36 | + |
| 37 | +## Context Assembly |
| 38 | + |
| 39 | +The killer feature: `assemble_context` builds a complete LLM prompt from character profile + memories in one call. |
| 40 | + |
| 41 | +```python |
| 42 | +import anthropic |
| 43 | +from hippodid import HippoDid |
| 44 | + |
| 45 | +hd = HippoDid(api_key="hd_your_key") |
| 46 | +claude = anthropic.Anthropic() |
| 47 | + |
| 48 | +# One call: fetch profile + search memories + format prompt |
| 49 | +context = hd.assemble_context(char_id, "What should we refactor?", strategy="task_focused") |
| 50 | + |
| 51 | +response = claude.messages.create( |
| 52 | + model="claude-sonnet-4-20250514", |
| 53 | + max_tokens=1024, |
| 54 | + system=context.formatted_prompt, |
| 55 | + messages=[{"role": "user", "content": "What should we refactor?"}], |
| 56 | +) |
| 57 | + |
| 58 | +# Save the exchange |
| 59 | +hd.add_memory(char_id, f"Discussed refactoring: {response.content[0].text}") |
| 60 | +``` |
| 61 | + |
| 62 | +### Assembly Strategies |
| 63 | + |
| 64 | +Same character data, different prompt formatting: |
| 65 | + |
| 66 | +| Strategy | Best For | Emphasis | |
| 67 | +|---|---|---| |
| 68 | +| `default` | General use | system_prompt + profile + memories by relevance | |
| 69 | +| `conversational` | Chat agents | Personality/tone, recent episodic memories | |
| 70 | +| `task_focused` | Work agents | Rules/constraints, project context, decisions | |
| 71 | +| `concierge` | Service agents | Preferences/history, proactive suggestions | |
| 72 | +| `matching` | Cross-character | Profile-heavy, minimal memories | |
| 73 | + |
| 74 | +## Async Support |
| 75 | + |
| 76 | +```python |
| 77 | +from hippodid import AsyncHippoDid |
| 78 | + |
| 79 | +async with AsyncHippoDid(api_key="hd_your_key") as hd: |
| 80 | + char = await hd.create_character(name="Ada") |
| 81 | + await hd.add_memory(char.id, "Ada loves async Python") |
| 82 | + context = await hd.assemble_context(char.id, "async patterns") |
| 83 | +``` |
| 84 | + |
| 85 | +## Character Templates & Batch Create |
| 86 | + |
| 87 | +```python |
| 88 | +# Create a template for batch character creation |
| 89 | +template = hd.create_character_template( |
| 90 | + name="Sales Rep", |
| 91 | + field_mappings=[ |
| 92 | + {"sourceColumn": "name", "targetField": "name"}, |
| 93 | + {"sourceColumn": "crm_id", "targetField": "externalId"}, |
| 94 | + ], |
| 95 | +) |
| 96 | + |
| 97 | +# Batch create from a list of dicts (also accepts pandas DataFrames or file paths) |
| 98 | +job = hd.batch_create_characters( |
| 99 | + template_id=template.id, |
| 100 | + data=[ |
| 101 | + {"name": "Alice", "crm_id": "SF-001"}, |
| 102 | + {"name": "Bob", "crm_id": "SF-002"}, |
| 103 | + ], |
| 104 | + external_id_column="crm_id", |
| 105 | +) |
| 106 | + |
| 107 | +# Poll for completion |
| 108 | +status = hd.get_batch_job_status(job.job_id) |
| 109 | +``` |
| 110 | + |
| 111 | +## Agent Config |
| 112 | + |
| 113 | +Store LLM preferences per character: |
| 114 | + |
| 115 | +```python |
| 116 | +hd.set_agent_config( |
| 117 | + char_id, |
| 118 | + system_prompt="You are Ada, a senior engineer.", |
| 119 | + preferred_model="claude-sonnet-4-20250514", |
| 120 | + temperature=0.3, |
| 121 | + tools=["code_search", "run_tests"], |
| 122 | +) |
| 123 | + |
| 124 | +# RAG: ask a question using character's memories + stored agent config |
| 125 | +result = hd.ask(char_id, "What patterns should we use?", use_agent_config=True) |
| 126 | +print(result.answer) |
| 127 | +``` |
| 128 | + |
| 129 | +## Memory Modes |
| 130 | + |
| 131 | +Control how `add_memory` processes content: |
| 132 | + |
| 133 | +```python |
| 134 | +hd.set_memory_mode(char_id, "VERBATIM") # Store exact content, zero LLM cost |
| 135 | +hd.set_memory_mode(char_id, "EXTRACTED") # AI extracts structured facts (default) |
| 136 | +hd.set_memory_mode(char_id, "HYBRID") # Both extraction + verbatim (Business+) |
| 137 | +``` |
| 138 | + |
| 139 | +## Clone Characters |
| 140 | + |
| 141 | +```python |
| 142 | +clone = hd.clone_character( |
| 143 | + char_id, |
| 144 | + "Ada-Staging", |
| 145 | + copy_memories=True, |
| 146 | + copy_tags=True, |
| 147 | +) |
| 148 | +print(f"Cloned: {clone.character.id}, {clone.memories_copied} memories copied") |
| 149 | +``` |
| 150 | + |
| 151 | +## Framework Examples |
| 152 | + |
| 153 | +See the `examples/` directory: |
| 154 | + |
| 155 | +- **[claude_hippodid_direct.py](examples/claude_hippodid_direct.py)** -- 10-line Claude integration |
| 156 | +- **[langchain_hippodid_memory.py](examples/langchain_hippodid_memory.py)** -- Drop-in BaseChatMemory subclass |
| 157 | +- **[crewai_hippodid_memory.py](examples/crewai_hippodid_memory.py)** -- CrewAI agents with HippoDid identity |
| 158 | +- **[openai_agents_hippodid.py](examples/openai_agents_hippodid.py)** -- OpenAI Agents SDK with memory tools |
| 159 | +- **[luxury_concierge.py](examples/luxury_concierge.py)** -- Assembly strategy showcase |
| 160 | +- **[salesforce_to_hippodid.py](examples/salesforce_to_hippodid.py)** -- End-to-end batch pipeline |
| 161 | +- **[healer_matching.py](examples/healer_matching.py)** -- Cross-character matching |
| 162 | + |
| 163 | +## API Reference |
| 164 | + |
| 165 | +Full documentation at [docs.hippodid.com](https://docs.hippodid.com). |
| 166 | + |
| 167 | +## License |
| 168 | + |
| 169 | +MIT |
0 commit comments