popoto.extraction.claude¶
popoto.extraction.claude
¶
Claude (Anthropic) memory-extraction provider.
Wraps the Anthropic Messages API behind the AbstractExtractionProvider interface. Requires the anthropic package (pip install popoto[anthropic]).
Opt-in only: import popoto and import popoto.extraction never
import anthropic -- this module is imported lazily by callers who
want LLM-based extraction, mirroring popoto.embeddings.openai's pattern.
Example
from popoto.extraction.claude import ClaudeExtractionProvider provider = ClaudeExtractionProvider(api_key="your-key") facts = provider.extract("Alice met Bob at the conference in Paris.")
EXTRACTION_MODEL = 'claude-opus-4-8'
module-attribute
¶
Pinned model for Claude-based extraction. Not user-configurable.
EXTRACTION_MAX_TOKENS = 4096
module-attribute
¶
Pinned max_tokens for Claude-based extraction. Not user-configurable.
EXTRACTION_PROMPT = 'You are a memory-extraction engine for an AI agent. Given a block of text (typically an LLM\'s response during a conversation), extract the discrete, independently-useful facts it contains.\n\nFor each fact:\n- "text": a short, self-contained statement of the fact, written so it makes sense on its own without the surrounding conversation.\n- "entities": the proper nouns / named entities mentioned in the fact (people, places, organizations, products, dates treated as named references, etc.). Use an empty list if none are present.\n- "importance": a score from 0.0 to 1.0 for how important this fact is likely to be to remember later (0.0 = trivial/filler, 1.0 = critical, load-bearing information).\n- "confidence": a score from 0.0 to 1.0 for how certain the source text is asserting this fact (0.0 = highly speculative or hedged, 1.0 = stated as definite fact).\n\nOnly extract facts that carry real informational content -- skip greetings, filler, and purely conversational scaffolding. If the text contains no extractable facts, return an empty "facts" array.'
module-attribute
¶
Pinned system prompt for Claude-based extraction. Not user-configurable.
FACTS_SCHEMA = {'type': 'object', 'properties': {'facts': {'type': 'array', 'items': {'type': 'object', 'properties': {'text': {'type': 'string'}, 'entities': {'type': 'array', 'items': {'type': 'string'}}, 'importance': {'type': 'number'}, 'confidence': {'type': 'number'}}, 'required': ['text', 'entities', 'importance', 'confidence'], 'additionalProperties': False}}}, 'required': ['facts'], 'additionalProperties': False}
module-attribute
¶
JSON schema for structured extraction output. Not user-configurable.
ClaudeExtractionProvider
¶
Bases: AbstractExtractionProvider
Claude (Anthropic) memory-extraction provider.
Opt-in provider that calls the Anthropic Messages API once per
extract() call, using structured JSON-schema output
(output_config.format) to get typed facts back directly -- no
tool_use, no assistant-turn prefill (which 400s on this model
family).
Model and prompt are pinned module constants (EXTRACTION_MODEL,
EXTRACTION_PROMPT), not constructor kwargs, per this project's
experimental-constant convention.
On any API or parse failure, extract() logs a warning and returns
an empty list -- it never raises, so a flaky extraction call never
crashes the caller's turn loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Anthropic API key. If None, reads from the
|
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
Source code in src/popoto/extraction/claude.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
extract(text)
¶
Extract facts from text via one Claude API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to extract facts from. |
required |
Returns:
| Type | Description |
|---|---|
List[ExtractedFact]
|
List of ExtractedFact. Empty list if the text is empty/blank, |
List[ExtractedFact]
|
no facts were found, or the API call/parse failed (a warning |
List[ExtractedFact]
|
is logged in the failure case). |