AgentSkillsCN

Orchestration

编排

SKILL.md

Orchestration Skill

Scope: LLM orchestration — node behavior, state machines, prompts

This skill applies when working on LangGraph workflow, node implementations, prompt engineering, or context management.


Graph Flow

code
                              ┌─────────────┐
                              │  ACT QUICK  │ ← Single tool call (simple reads)
                              └──────┬──────┘
                                     │
┌────────────┐   quick_mode?   ┌─────▼─────┐   ┌───────────┐
│ UNDERSTAND │───────────────▶│   REPLY   │──▶│ SUMMARIZE │
└─────┬──────┘                 └───────────┘   └───────────┘
      │
      │ !quick_mode
      ▼
┌───────┐   ┌─────────────────┐   ┌───────┐   ┌───────────┐
│ THINK │──▶│    ACT LOOP     │──▶│ REPLY │──▶│ SUMMARIZE │
└───────┘   └─────────────────┘   └───────┘   └───────────┘

Node Responsibilities

NodePurposeKey Output
UnderstandMemory manager: entity resolution, context curation, quick mode detectionreferenced_entities, entity_curation
ThinkConversation architect: plan steps, propose checkpoints, manage multi-turn flowssteps[], decision (plan_direct/propose/clarify)
ActExecute via CRUD tools or generate contentTool calls, step_complete
ReplyPresent execution results with personaNatural language response
SummarizeCompress context, persist registry and conversationUpdated conversation state

Step Types

TypePurposeDB Calls?Content Created?
readFetch data from databaseYesNo
writePersist content to databaseYesNo
analyzeReason over dataNoNo
generateCreate new content (stored as pending artifact)NoYes

Key insight: generate creates content; write persists it. Never use write to create new content.


Subdomains

SubdomainTables
inventoryinventory, ingredients
recipesrecipes, recipe_ingredients
shoppingshopping_list
meal_plansmeal_plans
taskstasks
preferencespreferences

Entity Management (SessionIdRegistry)

Single source of truth. LLMs never see UUIDs — only simple refs.

Ref Naming Convention

  • {type}_{n} — Entity from database: recipe_1, inv_5, meal_3
  • gen_{type}_{n} — Generated but not yet saved: gen_recipe_1

Entity Lifecycle

ActionSet ByWhen
readCRUD layerAfter db_read returns data
createdCRUD layerAfter db_create succeeds
updatedCRUD layerAfter db_update succeeds
deletedCRUD layerAfter db_delete succeeds
generatedAct nodeAfter generate step produces content
linkedCRUD layerFK lazy registration (e.g., recipe_id in meal_plans)

ID Translation Flow

code
db_read → SessionIdRegistry.translate_read_output() → LLM sees recipe_1
LLM says "delete recipe_1" → SessionIdRegistry.translate_filters() → db_delete with UUID

V9: Unified Data Access

python
# Single source of truth for entity data availability
registry.get_entity_data(ref) → dict | None

# Unified modification for gen_* artifacts
registry.update_entity_data(ref, content) → bool

Three-Layer Context Model

LayerWhatOwnerSurvives Turns?
EntityRefs, labels, statusSessionIdRegistryYes
ConversationUser/assistant messagesSummarizeYes
ReasoningWhat LLMs decided (TurnExecutionSummary)SummarizeYes (last 2)

Entity Context Delineation in Prompts

code
## Generated Content (NOT YET SAVED)
- gen_recipe_1: Thai Curry (recipe) [unsaved]

## Recent Context (last 2 turns)
- recipe_1: Butter Chicken (recipe) [read:full]
- inv_1: Eggs (inv) [read]

## Long Term Memory (retained from earlier)
- gen_meal_plan_1: Weekly Plan (meal, turn 2) — *User's ongoing goal*

Context API

Location: src/alfred/context/

FilePurpose
entity.pyget_entity_context(), format_entity_context()
conversation.pyget_conversation_history(), format_conversation()
reasoning.pyget_reasoning_trace(), format_reasoning()
builders.pybuild_think_context(), build_act_context(), build_reply_context()

Node-Specific Builders

python
build_understand_context(state) → dict  # Full context for curation
build_think_context(state) → dict       # Refs + labels for planning
build_act_context(state) → dict         # Full data for execution
build_reply_context(state) → dict       # Labels for presentation

Prompt Structure

Runtime templates: prompts/*.md

TemplateNode
system.mdAll nodes (identity/capabilities)
understand.mdUnderstand node
think.mdThink node
act/base.md, act/crud.md, act/*.mdAct node (step-type specific)
reply.mdReply node
summarize.mdSummarize node

Prompt assembly: src/alfred/prompts/injection.py


Key Files

FilePurpose
src/alfred/graph/workflow.pyLangGraph definition, run_alfred() entry point
src/alfred/graph/state.pyAlfredState TypedDict, all Pydantic contracts
src/alfred/graph/nodes/*.pyNode implementations
src/alfred/core/id_registry.pySessionIdRegistry — ref↔UUID translation
src/alfred/context/builders.pyContext API builders
src/alfred/prompts/injection.pyDynamic prompt assembly

Common Patterns

Quick Mode Detection (Understand)

  • Single-part request
  • Single-domain
  • READ only (no writes, generates, or knowledge questions)

Think Decisions

DecisionWhen
plan_directClear request, can execute immediately
proposeComplex workflow, present plan to user first
clarifyAmbiguous request, need more info

Recent Context = Already Loaded

If Think sees entities in "Recent Context (last 2 turns)":

  • DON'T: Plan a read step to "read all recipes"
  • DO: Plan an analyze step referencing those entities by ref

Related Docs