LangChain guide
Expose Ayneye video artifacts as auditable LangChain tools.
The safe pattern is not one giant video tool. Split state, evidence, cost, and Ask Video into separate read-only tools so every agent step can be logged and reviewed.
Tool architecture
| Tool | Input | Output | Review rule |
|---|---|---|---|
| fetch_video_world_state | video_id | scene_graph.json summary | No unsupported identity or intent claims |
| fetch_video_evidence | video_id + evidence_ref | time span + notes | Answer must cite evidence_ref |
| fetch_video_cost | video_id | cost.json and limits | Expose budget state |
| ask_video_with_evidence | video_id + question | answer or insufficient-evidence | Never guess when evidence is missing |
LangChain implementation sketch
from langchain_core.tools import tool
@tool
def fetch_video_world_state(video_id: str) -> dict:
"""Read Ayneye scene_graph.json for a processed video."""
return ayneye.scene_graph(video_id)
@tool
def fetch_video_evidence(video_id: str, evidence_ref: str) -> dict:
"""Fetch traceable evidence span and review notes."""
return ayneye.evidence(video_id, evidence_ref)
@tool
def fetch_video_cost(video_id: str) -> dict:
"""Read cost.json, detector mode, fallback flags, and limits."""
return ayneye.cost(video_id)
SYSTEM = """
Use only Ayneye artifacts supplied by tools.
Cite evidence_ref for every factual claim.
Return INSUFFICIENT_EVIDENCE when evidence is missing.
Never infer identity, intent, or trigger physical actions.
"""Production-readiness checklist
- Log tool name, input, artifact version, and output state.
- Persist evidence_ref citations in the final answer.
- Block unscoped video IDs and cross-tenant artifact reads.
- Expose review-required states in the UI.
- Test with ambiguous questions and verify refusal behavior.