ai-file-analysis-agent
Design, configure, ground, and verify production-grade AI file analysis agents using direct file APIs, negative constraint prompts, and robust conversational loops. Do not use for generic document generation or unstructured web search.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- ai-file-analysis-agent
- description
- Design, configure, ground, and verify production-grade AI file analysis agents using direct file APIs, negative constraint prompts, and robust conversational loops. Do not use for generic document generation or unstructured web search.
02 资源文件 5
- 参考文档CARD.md5.0 KB
- 参考文档config.default.yaml1.2 KB
- 参考文档references/direct-api-vs-rag-guide.md2.9 KB
- 参考文档references/grounding-and-role-catalog.md4.2 KB
- 脚本scripts/file_agent_cli.py20.5 KB
03 SKILL.md 正文
AI File Analysis Agent
ai-file-analysis-agent is a deep-module agent skill for engineering, deploying, and verifying document-grounded AI file analysis assistants. Distilled from Eva J Patel's curriculum, it equips agents with architectural decision rules for Direct File API versus Chunked RAG, prompt grounding guardrails that eliminate hallucinations, and resilient conversational loops.
See CARD.md for companion quick reference cards, CLI commands, and stage matrices.
Core Operational Pillars
Every document analysis engagement enforces three architectural pillars:
- The Visual Brief — Interactive HTML briefs generated in
%TEMP%/ai-file-analysis-agent-<timestamp>.htmlwith live Mermaid.js pipeline routing topologies, 10-point grounding audits, and context decision matrices. - The Mandatory Checkpoint — Human-in-the-loop validation via
implementation_plan.mdwithRequestFeedback: true. The agent must halt and await user confirmation before modifying file agent configurations or dispatching live batch API calls. - Behavioral Boundaries & Anti-Patterns — Rigid negative guardrails that reject ungrounded prose, untethered pre-training speculations, unvalidated file types, and silent interactive inputs.
Authoritative Tooling & Execution Seams
The skill provides deterministic, non-interactive execution engines in scripts/:
python scripts/file_agent_cli.py validate-file <path> [--json]: Non-interactive file validation checking path existence, extension whitelist, and size thresholds.python scripts/file_agent_cli.py assemble-prompt [--role <role>] [--json]: Assembles authoritative system instructions viaGroundingCatalogwith 10 grounding rules and specialized role addenda.python scripts/file_agent_cli.py dry-run --file <path> --question "<q>" [--role <role>]: Prepares staged session payload viaFileAnalysisEngine.prepare_sessionwithout external network calls.python scripts/file_agent_cli.py audit-response --text "<text>" [--file <path>] [--json]: Audits model output against the 10 Negative Grounding Constraints viaGroundingAuditor, scoring compliance and detecting inference tags.
Consult co-located architectural reference guides in references/:
- If choosing between full document streaming and vector retrieval, consult
direct-api-vs-rag-guide.mdfor architectural trade-offs, latency budgets, and file size limits. - If designing specialized agent personas or strict anti-hallucination instructions, consult
grounding-and-role-catalog.mdfor the 10 Negative Grounding Constraints and 4 domain profiles.
Execution Stages
Stage 1: Pre-flight Ingestion & Boundary Validation
Verify and sanitize input file paths before touching external API endpoints or allocating memory.
Procedure
- Verify target file existence and ensure the path resolves to a regular filesystem file.
- Filter the file extension against the configured whitelist (
.pdf,.docx,.csv,.txt). Reject unsupported formats immediately with clear guidance. - Check file size against the direct upload threshold (
max_direct_file_bytes = 50 MB). - Sanitize path references to prevent directory traversal or terminal injection.
- Invoke
python scripts/file_agent_cli.py validate-file <path>to confirm validation status.
Completion Gate:
Input file existence, extension whitelist, and size bounds verified
Stage 2: Context Architecture & Retrieval Triage
Evaluate document size and query characteristics to select between Direct File API Upload and Chunked Vector RAG per direct-api-vs-rag-guide.md.
Procedure
- If the document is $\le 50$ MB and represents a discrete analytical artifact (report, contract, paper, dataset), route to Direct File API.
- If the document exceeds context bounds or requires multi-document semantic retrieval across a large corpus, route to Chunked RAG.
- When using Direct File API, upload the document once using
client.files.create(file=file, purpose="user_data")and retain the resultingfile_id. - Avoid redundant uploads across conversational follow-ups by binding the stored
file_idto subsequent turn messages.
Completion Gate:
Direct File API vs Chunked RAG context architecture selected
Stage 3: Grounded Instructions & Role Specialization
Assemble system instructions embedding the 10 Negative Grounding Constraints and domain-specific role configurations from grounding-and-role-catalog.md.
Procedure
- Inject the 10 negative grounding constraints into the system instruction block:
- Primary source invariant, direct answers, zero fabrication.
- Explicit admission when information is missing: "The provided file does not contain enough information to answer this question."
- Distinction between methods, results, and conclusions for analytical queries.
- Requirement to prefix deductive leaps with
[INFERENCE].
- Append specialized domain profiles when requested:
research: Isolates hypotheses, empirical findings, and author conclusions.legal: Analyzes contractual terms, liabilities, and termination clauses.resume: Extracts verified technical capabilities and career achievements.tabular: Audits schemas, null distributions, and numeric metrics.
- Validate assembled prompt via
python scripts/file_agent_cli.py assemble-prompt --role <role>.
Completion Gate:
Grounded system instructions assembled with negative constraints and role profile
Stage 4: Conversational State Loop & Fault Tolerance
Implement the interaction engine with defensive exception shielding and session state management.
Procedure
- Enforce turn-level input sanitization: strip whitespace and ignore empty prompts.
- Implement explicit termination triggers (
exit,quit) that cleanly release held file handles. - Shield API dispatch calls inside structured
try/exceptblocks to intercept rate limits, timeout exceptions, and API transport errors. - Render output streaming or clean markdown responses with formatted headings and bullet points.
- In automated environments, use
python scripts/file_agent_cli.py dry-runto verify structured input formatting. - Verify model response adherence against the 10 negative grounding constraints using
GroundingAuditor.auditorpython scripts/file_agent_cli.py audit-response.
Completion Gate:
Conversational turn loop implemented with defensive input and error shielding
Stage 5: Security Hardening & PII Quarantine
Apply zero-trust security practices across credentials, document storage, and instruction hierarchies.
Procedure
- Secure credential injection: Load API keys strictly from environment variables (
OPENAI_API_KEY). Never hardcode secrets in source or commit.envfiles. - Defense against document prompt injection: Frame file content strictly as data payloads (
input_file), isolating it from administrative system instructions. - PII and sensitive data handling: Sanitize temporary file caches and delete ephemeral uploads on session exit.
- Verify non-interactive execution: Ensure all production scripts execute without hanging on interactive standard input.
Completion Gate:
Environment key isolation verified and document injection defense enforced
Anti-Patterns
- Premature File Upload — Uploading documents to external APIs before validating file existence, size thresholds, and extension whitelists, leading to wasted bandwidth and unhandled API errors.
- Hallucinatory Context Filling — Allowing the agent to speculate or answer questions from general pre-training weights when the uploaded file lacks supporting evidence, rather than stating context absence.
- Redundant Per-Turn Upload — Re-uploading the same file on every conversational query instead of caching and referencing the persistent
file_idacross session turns. - Unbounded Extension Ingestion — Accepting arbitrary file extensions (
.exe,.bin,.py) without validation, exposing the system to binary corruption or execution exploits. - Hardcoded Secret Ingestion — Embedding API credentials directly into Python scripts or commit history instead of injecting via environment variables.
- Interactive Hanging Script — Invoking
input()or blocking stdin prompts inside automated pipelines, causing headless execution runners to freeze indefinitely.
04 同仓库更多 Skills
ui-behavior-primitive-architect
Architect, audit, and verify zero-dependency headless UI behavior primitives, WebMCP agent bridges, WAI-ARIA/SSR/RTL tri-modal checks, and framework expert routing. Do not use for static CSS theme styling or backend database migrations.
trustgraph-ontology-governor
Govern knowledge graphs, SHACL-AF triple policies, OntologyRAG subclass validation, PROV-O dual named graphs, and Laya entropy decision scoring. Do not use for relational SQL queries or generic web scraping.
shim-harness-governor
Govern universal CLI agent loops, 4-tier tool permissions, ancestor-symlink workspace sandboxes, deterministic-first command routing, collision-safe MCP namespacing, and layered skill loading. Do not use for static UI styling or external SQL analytics.
graphiti-zep-memory-governor
Govern bi-temporal knowledge graphs with Graphiti future-edge clamping, MinHash/LSH entity dedup, RRF/MMR reranking, and Zep typed ontologies. Do not use for static SQL joins or generic web crawling.
agora-mcp-workbench-architect
Architect, audit, and orchestrate Agora Workbench MCP servers, loopback sidecars, unified state graphs, gateway/dispatcher connectors, and policy-enforced data lakes. Do not use for static frontend CSS styling or non-MCP desktop GUI automation.
skill-eval-assurance-runner
Evaluate and assure agent skills using small-N Wilson confidence intervals, unbiased pass^k reliability, deterministic trajectory graders, preflight boundary honesty, and sealed digest verification. Do not use for subjective prose review or unconstrained production deployment.