wassemgtk commited on
Commit
0d0ea70
·
verified ·
1 Parent(s): c74fc3a

Add project agent contract

Browse files
Files changed (1) hide show
  1. AGENTS.md +142 -0
AGENTS.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Project: GLM Visual Variable Runtime
2
+
3
+ ## Mission
4
+
5
+ Build an OpenAI-compatible multimodal gateway called:
6
+
7
+ glm-5.2-visual-runtime
8
+
9
+ The gateway must make the text-only GLM-5.2 model appear to support persistent image input across chat turns, OCR and document understanding, object-level color and style extraction, chart-to-data extraction, visual questions, presentation generation based on visual references, and references such as "this image", "those colors", "that chart", and composed multi-image/property references.
10
+
11
+ This project must not train, fine-tune, or modify GLM-5.2. The image is not converted into a permanent caption or inserted as visual tokens. Instead, every uploaded image becomes a persistent visual variable with lazily generated typed views.
12
+
13
+ Example:
14
+
15
+ img_01.original
16
+ img_01.thumbnail
17
+ img_01.ocr
18
+ img_01.objects
19
+ img_01.palette
20
+ img_01.presentation_theme
21
+ img_01.chart
22
+ img_01.chart.data_table
23
+
24
+ GLM-5.2 receives only the compact structured evidence needed for the current request.
25
+
26
+ ## Non-negotiable requirements
27
+
28
+ 1. No GPU training.
29
+ 2. No modification of GLM-5.2 weights.
30
+ 3. The public API must support OpenAI-compatible request formats.
31
+ 4. The original image must be stored and remain retrievable.
32
+ 5. Expensive visual analysis must run lazily, only when requested.
33
+ 6. Derived visual views must be cached by image hash and lens version.
34
+ 7. Later turns must work without uploading the image again.
35
+ 8. Every extracted value must retain provenance: asset ID, bounding box or source region, extraction method, confidence, and lens version.
36
+ 9. Do not send an entire OCR transcript to GLM unless the task requires it.
37
+ 10. Do not let GLM estimate chart numbers when they can be calculated from extracted structured data.
38
+ 11. Do not regenerate exact OCR strings when they can be copied from evidence.
39
+ 12. The gateway must support cloud mode with no local GPU.
40
+ 13. All model providers must be replaceable through interfaces.
41
+ 14. Build API and integration tests before adding a user interface.
42
+
43
+ ## Architecture
44
+
45
+ Implement this processing flow:
46
+
47
+ OpenAI-compatible request
48
+ |
49
+ v
50
+ Request normalizer
51
+ |
52
+ v
53
+ Conversation and visual asset ledger
54
+ |
55
+ v
56
+ Visual reference resolver
57
+ |
58
+ v
59
+ Intent and visual-program compiler
60
+ |
61
+ v
62
+ Lazy lens executor
63
+ | | | |
64
+ OCR Object Palette Chart
65
+ |
66
+ v
67
+ Compact evidence compiler
68
+ |
69
+ v
70
+ GLM-5.2
71
+ |
72
+ v
73
+ Text, JSON, table, image, or PPTX artifact
74
+
75
+ The public model ID is `glm-5.2-visual-runtime`. The internal reasoning model defaults to `glm-5.2`.
76
+
77
+ ## Repository structure
78
+
79
+ Use the monorepo layout requested by the project brief:
80
+
81
+ glm-vvr/
82
+ AGENTS.md
83
+ README.md
84
+ docker-compose.yml
85
+ .env.example
86
+ apps/api/
87
+ services/slides/
88
+ tests/
89
+ docs/
90
+
91
+ ## Public API
92
+
93
+ Implement:
94
+
95
+ POST /v1/responses
96
+ POST /v1/chat/completions
97
+ POST /v1/files
98
+ GET /v1/files/{file_id}
99
+ GET /v1/files/{file_id}/content
100
+ GET /health
101
+ GET /ready
102
+
103
+ `/v1/responses` is canonical. Support `input_image.image_url`, Base64 data URLs, `input_image.file_id`, chat completion `image_url` content parts, multiple images in one user message, and `previous_response_id`.
104
+
105
+ When a URL image is supplied, download and snapshot it immediately. Validate MIME type, file size, image dimensions, decoded file signature, redirect limits, and private-network or localhost URLs to prevent SSRF.
106
+
107
+ ## Runtime rules
108
+
109
+ - On image ingest, store the original image, create an `img_NN` asset, calculate SHA-256, generate a thumbnail and cheap visual fingerprint, and set the asset as active. Do not run OCR, object detection, or chart extraction until needed.
110
+ - Resolve references deterministically first. If confidence is below threshold, call GLM-5.2 with structured output and validate the result.
111
+ - Compile user requests into validated visual programs before executing lenses.
112
+ - Use compact task-specific visual evidence for GLM-5.2. Include exact values, units, uncertainty, and source region IDs. Never claim visual evidence contains absent information.
113
+
114
+ ## Lenses
115
+
116
+ Implement replaceable lenses for OCR, object grounding, palette extraction, chart extraction, and presentation theme derivation. Cache views by:
117
+
118
+ sha256(asset bytes) + lens name + lens version + canonicalized parameters
119
+
120
+ OCR should preserve exact Unicode, bounding boxes, reading order, tables, Markdown, and structured JSON. Chart extraction should produce reversible ChartIR and answer numeric chart questions from structured data, not model prose. Palette extraction should produce area, attention, and semantic palettes plus role-based design tokens with provenance and contrast checks.
121
+
122
+ ## Providers
123
+
124
+ Use interfaces for GLM-5.2, GLM-5V-Turbo, GLM-OCR, and fake deterministic providers. The MVP must default to API providers in cloud mode and fake providers in test mode. Do not self-host GLM-5.2 in the MVP.
125
+
126
+ ## Presentation generation
127
+
128
+ Use a separate TypeScript PptxGenJS service. GLM-5.2 produces a validated `PresentationSpec`; the renderer creates editable `.pptx` files with slide masters, extracted design tokens, editable charts/tables, source images where appropriate, speaker notes containing provenance when enabled, and low-confidence chart warnings.
129
+
130
+ ## Modes
131
+
132
+ - `cloud`: GLM-5.2 API, GLM-5V-Turbo API, GLM-OCR API, CPU image processing, no local GPU.
133
+ - `hybrid`: GLM-5.2 API, local or hosted OCR, optional local segmentation.
134
+ - `test`: deterministic fake providers, no external API calls.
135
+
136
+ ## Acceptance tests
137
+
138
+ The system must demonstrate persistent image references, palette-to-PPTX generation, object-region color extraction, exact OCR evidence, ChartIR-based chart answers, multi-image references, URL snapshot durability, duplicate hash view reuse, lazy lens execution, SSRF rejection, no-key test runs, and OpenAI Python client compatibility with only `base_url` changed.
139
+
140
+ ## Definition of done
141
+
142
+ The project is complete when it runs with Docker Compose, OpenAI Python client can call `/v1/responses`, images can be supplied by URL/Base64/file ID, later text-only turns can reference prior images, OCR/palette/object/chart lenses work through replaceable providers, ChartIR is emitted, editable PPTX files are generated, provenance and confidence are included, tests pass, no training code exists, default cloud deployment needs no local GPU, and docs explain how to add a visual lens without modifying GLM-5.2.