| name | dfs-guess |
| description | Demonstrates recursive self-invocation as a depth-first descent — a "20 questions" guesser. Walks the decision tree in tree.json by asking the user one yes/no question per node and invoking ITSELF on the chosen child, going deeper until it reaches a leaf entity and guesses it. |
DFS Guess (demo) — recursive self-invocation that descends one path
This skill demonstrates depth-first traversal via recursive self-invocation.
Unlike bfs-traverse (which enumerates every node level-by-level), this skill
follows a single path down the decision tree: it asks the user one yes/no
question, descends into the branch they pick, and invokes itself on that child
— going deeper and deeper until it reaches a leaf, which is its guess.
It reuses the same tree.json:
- Internal node (
label is a yes/no question, has two children):
children[0] is the YES branch, children[1] is the NO branch.
- Leaf node (
children is empty): label is a concrete entity — the guess.
The path of questions/answers is recorded in dfs.log so the descent is
observable.
Argument formats
This skill is both the entry point and the recursive step:
- Initial call (from the user): no argument. Start at the tree's
root,
depth 0, and create a fresh dfs.log.
- Recursive self-call:
node=<id> depth=<d> (always contains node=).
What to do
-
Detect the call type from $ARGUMENTS:
-
If it contains node=, this is a recursive call: parse the id and d.
-
Otherwise it is the initial call: read root from tree.json, set the
current id = root and d = 0, and create (overwrite) dfs.log with:
=== DFS guess over tree.json ===
-
Load the current node id from tree.json.
-
Base case — is it a leaf? If the node has no children, it is an entity.
Make your guess by asking the user (use the AskUserQuestion tool):
Is it a <label>? with options Yes / No.
- If Yes: append
GUESS: <label> — correct! to dfs.log, then read back
dfs.log and celebrate. Report the full question/answer path. Stop (do
not recurse).
- If No: append
GUESS: <label> — wrong to dfs.log. Tell the user the
entity isn't in this decision tree (the tree only knows the leaves in
tree.json). Stop.
-
Recursive step — internal node. Otherwise the label is a yes/no question.
Ask the user (use AskUserQuestion): <label> with options Yes / No.
-
Append to dfs.log (indented by depth for a path-like view):
depth <d>: <label> -> <Yes|No>
-
Pick the next node: children[0] if Yes, children[1] if No.
-
Invoke the dfs-guess skill again (yourself) with:
node=<next id> depth=<d+1>
Do not walk further inline — descend by invoking yourself.
The only way down a branch is to invoke yourself. You stop when you hit a leaf —
that leaf is the answer.