for-ais-only/metadata_docs/BUILDSUPON_AI_AGENT_GUIDE.md
buildsUpon Metadata: AI Agent GuideThe buildsUpon field in code example metadata enables AI agents to understand learning progressions and dependencies between examples. This guide explains how to consume and use this metadata effectively.
Each code example in the codeExamples array may include a buildsUpon field:
{
"id": "setnx_xx",
"description": "Conditional SET operations...",
"difficulty": "intermediate",
"buildsUpon": ["set_get"],
...
}
When a user asks about an example, construct the full learning path:
User asks about: "setnx_xx"
↓
Check buildsUpon: ["set_get"]
↓
Recommend: "First, understand set_get, then learn setnx_xx"
Implementation:
buildsUpon chains to build the complete prerequisite treebuildsUpon (foundational examples)When explaining an example, reference its prerequisites:
"This example builds on the foundational set_get example.
If you haven't seen that yet, I recommend understanding
basic SET/GET operations first."
Before recommending an example, check if the user understands prerequisites:
"This example requires understanding:
- set_get (foundational)
- setnx_xx (intermediate)
Would you like me to explain any of these first?"
Use buildsUpon to improve search results:
User searches: "advanced string operations"
↓
Filter examples by difficulty="advanced"
↓
For each result, show: "Builds on: [list of prerequisites]"
def get_prerequisites(example_id, examples_map):
"""Recursively build the prerequisite tree for an example."""
example = examples_map.get(example_id)
if not example or not example.get('buildsUpon'):
return [example_id] # Foundational example
prerequisites = []
for dep_id in example['buildsUpon']:
prerequisites.extend(get_prerequisites(dep_id, examples_map))
prerequisites.append(example_id)
return prerequisites
def has_circular_dependency(example_id, examples_map, visited=None):
"""Check if an example has circular dependencies."""
if visited is None:
visited = set()
if example_id in visited:
return True # Circular dependency detected
visited.add(example_id)
example = examples_map.get(example_id)
if not example or not example.get('buildsUpon'):
return False
for dep_id in example['buildsUpon']:
if has_circular_dependency(dep_id, examples_map, visited.copy()):
return True
return False
def validate_buildsupon_references(page_metadata):
"""Validate that all buildsUpon references exist on the page."""
example_ids = {ex['id'] for ex in page_metadata.get('codeExamples', [])}
for example in page_metadata.get('codeExamples', []):
for dep_id in example.get('buildsUpon', []):
if dep_id not in example_ids:
print(f"Warning: {example['id']} references non-existent {dep_id}")
buildsUpon values reference existing examplesbuildsUpon only references examples on the same page["step1", "step2"])buildsUponCombine buildsUpon with other fields for richer context:
{
"id": "advanced_pattern",
"description": "...",
"difficulty": "advanced",
"buildsUpon": ["basic_pattern"],
"languages": [...]
}
Use this to: