pynydus.engine.refinement¶
LLM refinement for spawning and hatching pipelines.
Spawning (Step 7): refine_skills / refine_memory use the configured
LLM tier to deduplicate memory records and normalize skill formatting.
The LLM always operates on already-redacted content.
Hatching (Step 3): refine_hatch uses the same tier to adapt or polish
reconstructed files for the target platform’s conventions.
Module Contents¶
Classes¶
A single refined memory record returned by the LLM. |
|
LLM response for memory deduplication and summarization. |
|
A single refined skill record returned by the LLM. |
|
LLM response for skill cleanup. |
|
A single file whose content has been adapted for the target platform. |
|
LLM response for cross-platform file adaptation. |
Functions¶
Return all |
|
Tokens present in original but absent from new. |
|
Load the AGENT_SPEC.md for a given agent type. |
|
Clean up skill names and formatting via the configured LLM tier. |
|
Deduplicate and summarize memory records via the configured LLM tier. |
|
Deduplicate and summarize memory records via LLM. |
|
Clean up skill names and formatting via LLM. |
|
Adapt or polish reconstructed files during hatching (Step 3) via LLM. |
Data¶
API¶
- pynydus.engine.refinement.logger¶
‘getLogger(…)’
- pynydus.engine.refinement.REFINEMENT_RETRY_LIMIT¶
3
- pynydus.engine.refinement._PLACEHOLDER_RE¶
‘compile(…)’
- pynydus.engine.refinement._extract_placeholders(text: str) set[str]¶
Return all
{{SECRET_NNN}}/{{PII_NNN}}tokens in text.
- pynydus.engine.refinement._find_missing_placeholders(original: str, new: str) set[str]¶
Tokens present in original but absent from new.
- class pynydus.engine.refinement.RefinedMemoryRecord(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelA single refined memory record returned by the LLM.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- original_ids: list[str]¶
None
IDs of the original records this was derived from (multiple if merged).
- label: pynydus.common.enums.MemoryLabel | None¶
None
Preserved label from the original record.
- class pynydus.engine.refinement.RefinedMemoryOutput(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelLLM response for memory deduplication and summarization.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- records: list[pynydus.engine.refinement.RefinedMemoryRecord]¶
None
The refined set of memory records. Fewer or equal to the input count.
- class pynydus.engine.refinement.RefinedSkillRecord(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelA single refined skill record returned by the LLM.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.
- class pynydus.engine.refinement.RefinedSkillsOutput(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelLLM response for skill cleanup.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- skills: list[pynydus.engine.refinement.RefinedSkillRecord]¶
None
The refined skills. Same count as input (1:1, no merging).
- class pynydus.engine.refinement.AdaptedFile(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelA single file whose content has been adapted for the target platform.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.
- class pynydus.engine.refinement.AdaptedFilesOutput(/, **data: typing.Any)¶
Bases:
pydantic.BaseModelLLM response for cross-platform file adaptation.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- files: list[pynydus.engine.refinement.AdaptedFile]¶
None
Adapted file contents. Only includes files that needed changes.
- pynydus.engine.refinement._MEMORY_SYSTEM_PROMPT = <Multiline-String>¶
- pynydus.engine.refinement._SKILL_SYSTEM_PROMPT = <Multiline-String>¶
- pynydus.engine.refinement._HATCH_SYSTEM_PROMPT = <Multiline-String>¶
- pynydus.engine.refinement._HATCH_POLISH_PROMPT = <Multiline-String>¶
- pynydus.engine.refinement._AGENT_SPEC_DIR¶
None
- pynydus.engine.refinement._load_agent_spec(agent_type: pynydus.common.enums.AgentType) str¶
Load the AGENT_SPEC.md for a given agent type.
- pynydus.engine.refinement.refine_skills(skills: pynydus.api.schemas.SkillsModule, llm_config: pynydus.llm.LLMTierConfig, spawn_log: list[dict] | None = None) pynydus.api.schemas.SkillsModule¶
Clean up skill names and formatting via the configured LLM tier.
Args: skills: Module containing skill records to refine. llm_config: LLM provider, model, and API key. spawn_log: If set, refinement log entries are appended here.
Returns: Updated SkillsModule with cleaned names and formatting.
- pynydus.engine.refinement.refine_memory(memory: pynydus.api.schemas.MemoryModule, llm_config: pynydus.llm.LLMTierConfig, spawn_log: list[dict] | None = None) pynydus.api.schemas.MemoryModule¶
Deduplicate and summarize memory records via the configured LLM tier.
Args: memory: Module containing memory records to refine. llm_config: LLM provider, model, and API key. spawn_log: If set, refinement log entries are appended here.
Returns: Updated MemoryModule with deduplicated/summarized records.
- pynydus.engine.refinement._refine_memory(partial: pynydus.api.schemas.EggPartial, llm_config: pynydus.llm.LLMTierConfig) pynydus.api.schemas.EggPartial¶
Deduplicate and summarize memory records via LLM.
Args: partial: EggPartial whose memory module will be refined in place. llm_config: LLM provider, model, and API key.
Returns: The same EggPartial with its memory module updated.
- pynydus.engine.refinement._refine_skills(partial: pynydus.api.schemas.EggPartial, llm_config: pynydus.llm.LLMTierConfig) pynydus.api.schemas.EggPartial¶
Clean up skill names and formatting via LLM.
Args: partial: EggPartial whose skills module will be refined in place. llm_config: LLM provider, model, and API key.
Returns: The same EggPartial with its skills module updated.
- pynydus.engine.refinement.refine_hatch(file_dict: dict[str, str], egg: pynydus.api.schemas.Egg, llm_config: pynydus.llm.LLMTierConfig, *, target: str | None = None, log: list[dict] | None = None, spawn_log: list[dict] | None = None, raw_artifacts: dict[str, str] | None = None) dict[str, str]¶
Adapt or polish reconstructed files during hatching (Step 3) via LLM.
Operates on a filename-to-content mapping with placeholders only. no disk I/O. Retries when redaction placeholders are dropped. on persistent failure, leaves affected paths unchanged.
Args: file_dict: Reconstructed files (paths relative to output root). egg: Egg being hatched (manifest, secrets metadata, agent type). llm_config: LLM provider, model, and API key. target: Explicit target platform type (e.g. “openclaw”). log: If set, hatch log entries (warnings, reverts) are appended here. spawn_log: Optional spawn pipeline log forwarded into the LLM context. raw_artifacts: Optional redacted
raw/snapshot for extra LLM context.Returns: Updated file dict (unchanged keys omitted from LLM output stay as in
file_dict).