-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Labels
ai-friendlyWell-documented task suitable for AI-assisted developmentWell-documented task suitable for AI-assisted developmentarea:harnessCoding agent harness integrationCoding agent harness integrationenhancementNew feature or requestNew feature or requestsdk:pythonPython SDK relatedPython SDK relatedsdk:typescriptTypeScript SDK relatedTypeScript SDK related
Description
Overview
Implement the schema handling module that converts developer schemas (Pydantic/Zod) into prompt suffixes, manages temp file lifecycle, performs cosmetic JSON repair, and validates output against the schema. Uses universal file-write strategy (no native --json-schema flags).
Branch: feat/harness-v2
Design doc: docs/design/harness-v2-design.md (Section 5)
Scope
Python (sdk/python/agentfield/harness/)
-
_schema.py:build_prompt_suffix(schema, cwd)→ appends OUTPUT REQUIREMENTS blockget_output_path(cwd)→ returns{cwd}/.agentfield_output.jsonget_schema_path(cwd)→ returns{cwd}/.agentfield_schema.jsonwrite_schema_file(schema, cwd)→ for large schemas (>4K tokens), write to filecosmetic_repair(raw_json: str)→ strip markdown fences, trailing commas, fix truncated bracketsparse_and_validate(file_path, schema)→ read file, parse JSON, validate against Pydantic modelcleanup_temp_files(cwd)→ delete output + schema files
- Tests: prompt suffix generation, cosmetic repair (markdown fences, trailing commas, truncated JSON), validation success/failure, large schema file-write, cleanup
TypeScript (sdk/typescript/src/harness/)
-
schema.ts:- Same functions adapted for Zod schemas
- Uses
zod-to-json-schemafor schema conversion
- Tests: mirror Python test coverage
Key Design Decisions
- Output file:
{cwd}/.agentfield_output.json(deterministic, dotfile, in cwd not /tmp) - Prompt suffix at END of user prompt (recency bias)
- Large schemas (>4K tokens): write schema to
.agentfield_schema.json, instruct agent to read it - Cosmetic repair handles: markdown fences, trailing commas, truncated closing brackets
Acceptance Criteria
- Prompt suffix correctly formatted with schema JSON
- Cosmetic repair handles all documented failure modes
- Parse+validate returns typed instance on success, None on failure
- Temp files cleaned up after use
- All tests pass
Dependencies
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ai-friendlyWell-documented task suitable for AI-assisted developmentWell-documented task suitable for AI-assisted developmentarea:harnessCoding agent harness integrationCoding agent harness integrationenhancementNew feature or requestNew feature or requestsdk:pythonPython SDK relatedPython SDK relatedsdk:typescriptTypeScript SDK relatedTypeScript SDK related