Agent core dev

From PyModel/pythinker-code · View interactive version

Agent core dev is an AI agent skill from the GitHub repository PyModel/pythinker-code. Use when developing in packages/agent-core-v2 (the DI × Scope agent engine) — adding or modifying a domain Service, choosing a LifecycleScope, wiring DI dependencies, splitting a domain across scopes, owning or migrating a config section, gating behavior behind an experimental flag, raising coded er

How to use this skill

Skill file

agent-core-dev

Develop packages/agent-core-v2 by lifecycle stage. This skill is self-contained: every rule, recipe, and red line lives in the stage files below — it does not delegate to packages/agent-core-v2/docs/.

agent-core-v2 is the new agent engine built on the DI × Scope architecture (a port of packages/agent-core). Everything resolves through the container: a service declares an identity, its dependencies, and a lifetime; the container decides construction, singleton-per-scope, ordering, and disposal. The stage files restate the rules in imperative form so you can work without reading the source docs.

Lifecycle at a glance

Orient → Design → Implement → Test → Verify
  │        │          │          │        │
  │        │          │          │        └─ lint:imports · typecheck · test · dep graph · red lines
  │        │          │          └─ test.md
  │        │          └─ implement.md (+ errors.md · flags.md · permission.md)
  │        └─ design.md
  └─ orient.md

Stages are ordered but not strictly linear: a test failure (stage 4) that reveals a wrong scope sends you back to design (stage 2); a CyclicDependencyError sends you to design.md §dependency-direction and implement.md §cycles.

Workflows

End-to-end procedures that span the stages. Reach for these before reading the stage files individually.

Stages

How to use this skill

Jump to the stage you are in and read that one file; each is self-contained and ends with its own red lines. Skim the global red lines below before submitting — they catch most mistakes across every stage. The repo's source of truth remains the code in packages/agent-core-v2/src/; this skill codifies the same rules so you do not have to re-derive them.

Global red lines

Invariants that hold across every stage. Each is expanded in the stage file noted.

  1. No new on a class whose constructor carries @IService deps — inject with @IX or accessor.get(IX). (implement.md)
  2. @IX decorates constructor parameters only; parameter order depends on construction (static-first for createInstance, @IX-first for scoped services). (service-authoring.md)
  3. Both interface and impl carry _serviceBrand; the createDecorator name is globally unique. (implement.md)
  4. Parent scope never depends on child scope — short-lived may inject long-lived, never the reverse. (orient.md)
  5. No cyclic dependencies — refactor (extract a third Service / use an event / re-scope); activation timing does not break dependency cycles. (design.md, implement.md)
  6. ServicesAccessor is valid only during invokeFunction — never stash it for async use. (implement.md)
  7. Scope follows state identity — no Map<sessionId, …> at App to fake per-session state. (design.md)
  8. Foundational layers never know upstream ones; business code never depends on the edge layer (gateway/rpc). (design.md)
  9. Throw coded errors; register codes centrally; branch on code across the wire, never instanceof. (errors.md)
  10. Gate unreleased behavior behind a flag contributed via registerFlagDefinition and resolved through IFlagService.enabled(id); no ad-hoc env toggles. (flags.md)
  11. Tests resolve the SUT by interface; shared stubs live under test/, never src/. (test.md)
  12. Config is the preference registry: only preferences that are persistable, schema'd, and user/operator-facing go in IConfigService. Domain-specific config (including env-only operational toggles) goes through registerConfigSection + envOverlay. Facts → IBootstrapService, and host invocation arguments (CLI flags, host identity headers, prompt identity) → BootstrapInput.args / IBootstrapService.args — never new per-domain runtime-options services; domain runtime state (cron/flags/model) never goes onto IBootstrapService; session state → Session scope; constants → code. Business domains never call IBootstrapService.getEnv() directly. (config.md)
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.