Skip to content

Commit 717608a

Browse files
andreisavuclaude
andauthored
Update README section examples to use factory functions (#8)
The code examples in sections 3, 4, and 4.1 showed sections as subclasses (e.g., class GameRulesSection) but the actual implementation uses factory functions (e.g., build_game_rules_section()). Updated the README to match the current implementation pattern. https://claude.ai/code/session_01EFFbwQAFBquperwEXsAmHd Co-authored-by: Claude <noreply@anthropic.com>
1 parent bc53808 commit 717608a

1 file changed

Lines changed: 30 additions & 33 deletions

File tree

README.md

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -158,53 +158,50 @@ The lucky dice tools (`pick_up_dice`, `throw_dice`) let players roll for bonus p
158158
Game rules start hidden and expand on demand. WINK provides a built-in `read_section` tool that agents can use to expand summarized sections:
159159

160160
```python
161-
class GameRulesSection(MarkdownSection[EmptyParams]):
162-
def __init__(self) -> None:
163-
super().__init__(
164-
title="Game Rules",
165-
key="rules",
166-
template="## Secret Trivia Game Rules...",
167-
summary="Game rules available. Use read_section('rules') to review.",
168-
visibility=SectionVisibility.SUMMARY, # Hidden until needed
169-
)
161+
def build_game_rules_section() -> MarkdownSection[EmptyParams]:
162+
return MarkdownSection[EmptyParams](
163+
title="Game Rules",
164+
key="rules",
165+
template="## Secret Trivia Game Rules...",
166+
summary="Game rules available. Use read_section('rules') to review.",
167+
visibility=SectionVisibility.SUMMARY, # Hidden until needed
168+
)
170169
```
171170

172171
### 4. Tools Attached to Sections (`sections.py`)
173172

174173
The hints section provides the hint tool:
175174

176175
```python
177-
class HintsSection(MarkdownSection[EmptyParams]):
178-
def __init__(self) -> None:
179-
super().__init__(
180-
title="Hints",
181-
key="hints",
182-
template="...",
183-
tools=(hint_lookup_tool,), # Tool scoped to this section
184-
)
176+
def build_hints_section() -> MarkdownSection[EmptyParams]:
177+
return MarkdownSection[EmptyParams](
178+
title="Hints",
179+
key="hints",
180+
template="...",
181+
tools=(hint_lookup_tool,), # Tool scoped to this section
182+
)
185183
```
186184

187185
### 4.1. Tool Policies (`sections.py`)
188186

189187
Tool policies enforce ordering constraints. The **Lucky Dice** mini-game demonstrates this - players can roll for bonus points, but must pick up the dice before throwing:
190188

191189
```python
192-
class LuckyDiceSection(MarkdownSection[EmptyParams]):
193-
def __init__(self) -> None:
194-
# Policy: throw_dice requires pick_up_dice to have been called first
195-
dice_policy = SequentialDependencyPolicy(
196-
dependencies={
197-
"throw_dice": frozenset({"pick_up_dice"}),
198-
}
199-
)
200-
201-
super().__init__(
202-
title="Lucky Dice",
203-
key="dice",
204-
template="...",
205-
tools=(pick_up_dice_tool, throw_dice_tool),
206-
policies=(dice_policy,), # Enforce tool ordering
207-
)
190+
def build_lucky_dice_section() -> MarkdownSection[EmptyParams]:
191+
# Policy: throw_dice requires pick_up_dice to have been called first
192+
dice_policy = SequentialDependencyPolicy(
193+
dependencies={
194+
"throw_dice": frozenset({"pick_up_dice"}),
195+
}
196+
)
197+
198+
return MarkdownSection[EmptyParams](
199+
title="Lucky Dice",
200+
key="dice",
201+
template="...",
202+
tools=(pick_up_dice_tool, throw_dice_tool),
203+
policies=(dice_policy,), # Enforce tool ordering
204+
)
208205
```
209206

210207
If the agent tries to call `throw_dice` before `pick_up_dice`, the policy blocks the call with an error message. Try it:

0 commit comments

Comments
 (0)