Files
misc-productivity-tools-OPEN/prompt-skill-template/advanced-ai-agent-design-framework.md
T

936 lines
20 KiB
Markdown
Raw Normal View History

2026-06-24 14:21:44 -06:00
# Advanced AI Agent Design Framework
This document is a practical framework for designing advanced autonomous AI agents: agents that can run in loops, call tools, manage context, maintain memory, use permissions, leave receipts, and improve over time.
It extends the prompt-skill-template repo from single reusable skills into a full agent system architecture.
This is not just a checklist. It is a system for building agents that can be handed over, inspected, improved, and operated by someone else.
The core idea:
```text
Intent
-> Identity and permissions
-> Orchestration
-> Context routing
-> Harness loop
-> Skill reasoning
-> Tool execution
-> Output routing
-> Memory and audit trail
-> Evaluation and improvement
```
The short version:
- Skills = thinking
- Resolvers = routing
- Harness = running
- Tools = doing
An advanced agent builder should be able to:
1. map a business process end to end
2. spot where an agent can replace or relieve a bottleneck
3. build the agent, tools, harness, routing, and memory around that bottleneck
4. measure whether the agent actually moved the pipeline
## System Layers
### Design Layer
Design defines what the agent is meant to accomplish before code or files are created.
Key questions:
- What outcome should exist when the task is complete?
- What artifact should be produced: Markdown, JSON, database row, alert, dashboard update, code change, or something else?
- What does "done" mean?
- Who owns the agent?
- What authority does the agent have?
- Can the agent transact, publish, message, schedule, delete, or modify records?
- Who is responsible when it acts?
Typical artifacts:
- `objective.md`
- `agent_identity.json`
- `permissions.json`
- `success_criteria.md`
### Runtime Layer: Harness
The harness is the execution engine.
It answers:
```text
How does this run?
```
The harness:
- runs the control loop
- calls models
- calls tools
- assembles context
- enforces constraints
- validates tool calls
- logs decisions and actions
- determines when the task is complete
Think of the harness as factory machinery. It does not define the agent's judgment. It executes the workflow.
The harness should be thin and tightly scoped to a specific task. It sits between the working system and the AI. It activates the AI to operate inside a controlled area, such as a repo, service folder, data pipeline, or workspace.
In a repo-style system, the harness may:
- run the model in a loop
- read specs, tasks, and data-operation files
- write controlled outputs into a service or working directory
- manage context loaded from specs and memory
- enforce safety and permission rules
Deterministic code still matters. Cron jobs, if/then rules, validators, parsers, and scripts should continue to handle deterministic work. The harness adds AI as the intelligence layer on top of that deterministic substrate.
Before any tool execution, the harness should:
- verify agent credentials
- check permission scope
- attach an identity signature or audit record
- enforce sandbox rules
- reject actions outside authority
### Deterministic Layer: Tools
Tools are reliable capabilities the agent can call.
They answer:
```text
What can the agent do repeatably?
```
Examples:
- ingest email, files, API data, or calendar data
- search and filter records
- write or update files
- create database rows
- call external APIs
- run code
- send notifications
- record payments or identity attestations
Tools should be deterministic, testable, and constrained. A tool should not be a vague instruction. It should have clear inputs, outputs, errors, and permissions.
Tools do the work. If skills are thinking, tools are doing.
### Cognitive Layer: Skills
Skills define how the agent thinks.
They answer:
```text
How should the agent interpret, decide, and communicate?
```
Skills include:
- role and behavior rules
- task methodology
- domain-specific judgment
- context-management rules
- output formats
- validation criteria
- escalation rules
Skills should be modular and reusable. A good skill can move across models, harnesses, and tool stacks.
Skills are procedural cognition. They encode how the agent should reason, judge, format, validate, and communicate.
### Identity And Personality Documents
Advanced agents often need more than a system prompt. Three durable documents are especially useful:
#### `SOUL.md`
`SOUL.md` defines who the agent is.
It can include:
- voice
- values
- operating principles
- what good output looks like
- what bad output looks like
- tone rules
- judgment rules
- behavioral preferences
This is not a task prompt. It is a constitution. Write it like you are briefing your smartest friend on how to represent a particular mind, taste, and standard of work.
#### `USER.md`
`USER.md` defines who the user is.
It is not a short bio. It is a deep user model.
It can include:
- how the user thinks
- what the user is building
- strengths
- blind spots
- temperament
- preferences
- important relationships and context
- what the user cares about
- what triggers frustration or trust
The better the agent understands the user, the better it can prioritize, communicate, and serve.
#### `AGENTS.md`
`AGENTS.md` defines operational rules.
It can include:
- what to check on every message or run
- what never to do
- how to handle failures
- lookup chains
- path rules
- escalation rules
- brain-first protocols
- multi-agent routing rules
`SOUL.md` says who the agent is. `USER.md` says who the agent serves. `AGENTS.md` says how the agent operates.
### Context Routing Layer: Resolvers
Resolvers decide what to load and where outputs go.
They answer:
```text
What context should be loaded?
Where should the result be stored or routed?
```
Context resolvers select:
- identity credentials
- permissions
- trust attestations
- relevant files
- prior summaries
- memory entries
- related receipts
- relevant tools and skills
Output resolvers route results to:
- Markdown
- JSON
- database rows
- dashboards
- audit logs
- memory stores
- optional signed or immutable records
Whenever a new skill or tool is added, the resolver layer must know how to find it. A capability exists only if the system can route work to it.
Resolvers route. They decide which context, skills, tools, memory, and output destinations are relevant to the current task.
### When A Resolver Should Be Markdown
Use Markdown when:
- routing requires judgment
- categories are fuzzy
- logic evolves often
- an LLM should interpret the routing rule
Example:
```markdown
# context_resolver.md
If the task involves analyzing a person, load:
- person identity document
- relevant social posts
- prior summaries
- recent interaction history
If the task involves documents, load:
- source documents
- prior chunk outputs
- related receipts
```
Markdown resolvers are flexible, easy to modify, and LLM-readable.
### When A Resolver Should Be Code
Use code when:
- rules are strict
- performance matters
- logic must be exact and repeatable
Example:
```python
def resolve_context(task_type):
if task_type == "diarization":
return ["pid.json", "activity.json"]
```
Code resolvers are fast, predictable, and testable.
### System Orchestration Layer
System orchestration defines who handles the work and how workflows are composed.
Typical artifact:
- `AGENTS.md`
This layer handles:
- task routing
- multi-agent coordination
- escalation logic
- agent role definitions
- workflow composition
Think of it as the org chart. It decides who does what, where work goes, and how specialized agents interact.
### State Layer: Memory
Memory defines what persists across steps, runs, and long-running workflows.
It answers:
```text
What must the agent remember?
How should that memory be retrieved?
How can we trust it later?
```
Memory can include:
- current task state
- full transcripts
- historical outputs
- prior receipts
- trends over time
- source references
- timestamps
- signatures or provenance records
Advanced agents need memory as an audit trail, not just storage.
### Infrastructure Layer
Infrastructure defines where and how the agent runs.
Questions:
- Does it run locally, in WSL, in Docker, in a VM, in a microVM, or in the cloud?
- Does each agent need its own sandbox?
- What filesystem, network, and credential access does it have?
- How are secrets stored?
- What happens when a run fails halfway?
### Evolution Layer
The system should be modular enough to improve without being rebuilt from scratch.
Ask whether you can swap:
- the model
- tools
- prompts
- skills
- resolvers
- memory backend
- sandbox runtime
- evaluation harness
Future-proofing means every layer has a boundary and a contract.
## Agent Flow
```text
Trigger
-> AGENTS.md selects agent or workflow
-> context resolver loads relevant context
-> harness executes loop
-> skill performs reasoning
-> tools execute actions
-> output resolver routes result
-> memory is updated
-> receipt is written
-> evaluator checks completion
-> ratchet improves the system when failures are found
```
Triggers can be:
- cron jobs
- manual starts
- API calls
- webhooks
- file changes
- incoming emails or messages
- scheduled monitors
## Process Discovery And Handoff
Before building an autonomous agent, map the human process.
A useful agent design should identify:
- the current business process from start to finish
- where work waits, repeats, or gets dropped
- which bottleneck the agent should replace, relieve, or accelerate
- what the agent must read
- what the agent must decide
- what the agent must do
- what the agent must produce
- how success will be measured
- who owns the result after the agent acts
The goal is not only to build an impressive agent. The goal is to move a real pipeline.
Useful measurements:
- cycle time reduced
- handoffs reduced
- manual steps removed
- error rate lowered
- response time improved
- more opportunities processed
- more work completed with the same team
- better follow-through on previously dropped tasks
If the agent cannot be connected to a bottleneck and a measurement, the design is probably still too abstract.
## Monetization Lens
When designing an agent, ask whether the system could eventually be sold, rented, or reused by someone else.
Possible sources of value:
- proprietary data collected during use
- a specialized workflow for a niche domain
- reusable skill packs
- deterministic tools
- receipts and eval cases produced over time
- domain-specific memory and context
- integrations that are painful to rebuild
## Suggested Folder Structure
```text
/agent-system
/harness
main.py
loop.py
config.yaml
/identity
SOUL.md
USER.md
agent_id.json
permissions.json
/skills
summarize.md
diarize.md
match.md
chunk_enrich.md
/resolvers
context_resolver.md
output_resolver.md
/agents
AGENTS.md
/tools
io.py
search.py
db.py
identity.py
wallet.py
attestation.py
/memory
/working
/persistent
/data
/inputs
/outputs
/logs
/sandbox
/runs
/evals
test_cases.md
failure_log.md
regression_checks.md
```
## Agent Build Checklist
Layer mapping:
1. Define objective -> design layer
2. Choose model -> harness
3. Define tools -> tools
4. Define data sources -> tools and resolvers
5. Write prompt or skill -> skills
6. Build harness loop -> harness
7. Add memory -> harness, tools, and skills
8. Add context control -> resolvers and harness
9. Define output -> skills and tools
10. Set trigger -> harness
11. Add logging -> harness
12. Add constraints -> harness and skills
13. Make it modular -> all layers
### 0. Identity And Trust Layer
This sits above every other layer.
Define:
- principal: the human or organization that owns the agent
- agent identity: DID, wallet, key, service account, or other identifier
- permissions: allowed actions, denied actions, approval thresholds
- attestations: reputation, certifications, provenance, prior actions
- payment layer: wallet, billing, payment endpoints, spending limits
- governance guarantees: immutable configs, version control, audit logs
Possible artifacts:
```text
/identity
agent_id.json
permissions.json
attestations.json
wallet.json
```
Design rule:
The agent should never act without knowing who it represents, what it is allowed to do, and how its actions will be audited.
### 1. Objective And Intent
Start here. Do not skip this layer.
Define:
- the job to be done
- the final output artifact
- the success criteria
- what "done" looks like
- what is explicitly out of scope
If the objective is fuzzy, the agent will wander.
### 2. LLM Selection
Choose the model strategy based on task requirements.
Decide:
- fast model or deeper reasoning model
- single model or multi-model architecture
- planner/executor split
- critic or evaluator model
- context window requirements
- cost constraints
- latency constraints
- privacy constraints
Advanced agents often benefit from model routing: use cheaper models for routine work and stronger models for high-stakes planning, synthesis, or verification.
### 3. Tools Layer
Define the actions the agent must be able to take.
Examples:
- ingest data
- search data
- write summaries
- update files
- call APIs
- run code
- send messages
- schedule events
- verify identity
- record audit events
- send or check payments
Tool design checklist:
- Are inputs constrained?
- Are outputs structured?
- Are errors explicit?
- Are permissions enforced?
- Is the tool deterministic?
- Can the tool be tested without an LLM?
- Does the tool leave a receipt or log entry?
Identity and payment tools may include:
```text
identity.py
verify_signature()
fetch_agent_credentials()
wallet.py
send_payment()
check_balance()
attestation.py
verify_provenance()
record_action()
```
### 4. Data And Context Sources
Define what the agent needs to see.
Examples:
- Markdown files
- JSON files
- databases
- APIs
- repo structure
- prior outputs
- logs
- receipts
- user identity documents
- calendar, email, or CRM data
Decide:
- What is static context?
- What is dynamic context?
- What should never be loaded?
- What requires trust verification?
- What requires human approval?
- What should be summarized before use?
Context is not just data. For advanced agents, context should be trusted, scoped, and traceable.
### 5. Prompt And Instruction Layer
This is the skill layer.
Define:
- system prompt
- role
- rules
- task instructions
- output format
- constraints
- escalation rules
- validation expectations
Example:
```text
You analyze emails for trends.
Only use available tools.
Operate within your permission scope.
Log all actions.
Reject tasks outside authority.
Output JSON with: topics, sentiment, anomalies, sources.
```
Keep prompts modular. A skill should be reusable across workflows.
### 6. Harness And Core Orchestration
The harness is the agent runtime.
It must handle:
- control loop: observe, decide, act, repeat
- tool execution: validate, run, return result
- context assembly: prompt, memory, current inputs, retrieved context
- stop conditions: determine when the task is complete
- error handling: retry, escalate, or stop
- logging: record decisions, tool calls, and results
- permissions: reject actions outside scope
The harness is procedural. It makes the agent run.
### 7. Memory System
Define two memory layers.
Working memory:
- current task state
- temporary notes
- active plan
- intermediate outputs
Persistent memory:
- full transcripts
- prior outputs
- historical receipts
- long-term trends
- user preferences
- reusable lessons
Memory storage can be:
- JSON files
- Markdown logs
- SQLite
- Postgres
- vector store
- graph database
Advanced memory should include:
- content
- timestamp
- source
- run ID
- agent ID
- signature or provenance record
- confidence or verification state
Memory should be treated as an audit trail, not just a pile of notes.
### 8. Context Management
Context management prevents agents from failing quietly.
Common failures:
- token overflow
- noisy context
- stale summaries
- duplicated data
- untrusted content
- missing source references
- irrelevant memory retrieval
Implement:
- clipping large outputs
- summarizing history
- deduplicating repeated data
- ranking context by relevance
- loading only verified or trusted sources when risk is high
- separating user instructions from untrusted retrieved content
- preserving source references
Advanced rule:
Context should be selected, scoped, and trusted. Loading more is not automatically better.
### 9. Output Handling
Define where outputs go and what form they take.
Possible destinations:
- Markdown
- JSON
- database
- dashboard
- audit log
- memory store
- external API
- human review queue
Output checklist:
- Is it human-readable?
- Is it machine-readable?
- Does it include sources?
- Does it include assumptions?
- Does it include validation status?
- Does it update memory?
- Does it create a receipt?
Prefer structured outputs for downstream automation, with optional Markdown for human review.
### 9.1. Sandbox
Define where the work happens in isolation.
Sandbox options:
- local folder sandbox
- WSL
- Docker
- VM
- microVM
- isolated cloud runner
Sandbox checklist:
- What files can be read?
- What files can be written?
- Is network access allowed?
- Are secrets available?
- Can subprocesses run?
- Are destructive actions blocked?
- Are credentials scoped per agent?
Identity isolation:
- each agent should run with its own credentials
- each agent should have its own permission scope
- high-risk agents should have separate sandboxes
- credentials should not be shared casually across workflows
### 10. Execution Layer
Define how the agent is triggered.
Trigger types:
- manual trigger
- cron job
- event-driven trigger
- webhook
- API call
- message queue
- file watcher
Authenticated triggers should verify:
- token
- signature
- agent identity
- user authorization
- spending or action limits
This layer is outside the harness, but required for real autonomous operation.
### 11. Observability, Checks, And Balances
The system must make agent behavior inspectable.
Log:
- who initiated the run
- what agent executed
- what model was used
- what tools were called
- what actions were taken
- what files or records changed
- what errors occurred
- what validation ran
- whether completion criteria were met
- signed proof or audit metadata where appropriate
Ask:
- Can you replay a run?
- Can you explain why the agent acted?
- Can you see what context it used?
- Can you detect incomplete work?
- Can you compare runs over time?
Advanced checker pattern:
- generator proposes or acts
- critic attacks assumptions
- synthesizer resolves conflicts
- monitor checks constraints, ethics, and scope
- evaluator checks the final artifact against success criteria
For high-stakes actions, require consensus or explicit approval before:
- financial transactions
- external communications
- data deletion
- permission changes
- strategic pivots
- irreversible writes
Adding independent checkers can improve:
- error detection
- hallucination suppression
- blind spot coverage
- policy compliance
- task completion reliability
### 12. Safety, Constraints, And Governance
Define what the agent is not allowed to do.
Controls:
- tool permissions
- read/write limits
- file path restrictions
- network restrictions
- spending limits
- approval gates
- immutable agent instructions
- versioned prompts
- external policy enforcement
- sandbox enforcement
- audit logging
Safety should not live only in the prompt. The harness, tools, filesystem, and execution environment should enforce constraints externally.
### 13. Modularity And Future-Proofing
Design every layer so it can be replaced.
Can you swap:
- model
- tool
- prompt
- skill
- resolver
- memory backend
- evaluation method
- sandbox
- trigger mechanism
- payment or identity provider
Future-proofing checklist:
- Each layer has a clear responsibility.
- Each artifact has a clear contract.
- Skills do not assume one specific model forever.
- Tools are callable outside the LLM.
- Context routing is separate from reasoning.
- Memory is separate from current task context.
- Receipts survive model and harness changes.
- Failures become regression cases or checklist updates.
The goal is a system where better models, better tools, and better infrastructure can be plugged in without throwing away the framework.
2026-06-26 10:05:11 -06:00
## Modularity
Build the pieces in this framework so that you can easily replace them and swap in updated components. The only component that might become long-lived are skills, but even they can be upated as the template in this repo is updated.