ogs.dsl.library¶
Reusable game factories for common patterns.
Reusable component factories for the Reactive Decision Pattern.
Each factory returns a pre-configured atomic game with the correct signature, encoding the shared structure found across negotiation and coalition patterns.
The Reactive Decision Pattern implements a decision-with-learning cycle triggered by environmental events. The order of operations is:
- Trigger Detection — sensors detect events (network, timer, market signals)
- Context Building — event processor transforms triggers + resources into an observation x in X and feasible decision set Y' ⊆ Y
- Reactive Decision — agent selects action y in Y' given observation, policy, and continuation context k: Y → R
- Outcome Evaluation — action evaluated against external world → utility r in R
- Learning — experience (coutility s in S) fed back to update policy and history
State evolution per step
g_0: X_T × X_C × P → U action decider (context + policy → action) g_1: H × U × R × P → P policy update (history + outcome → new policy) g_2: P × U × R × H → H history update (append (policy, action, outcome)) g_3: X_T × X_C × U → X_T × X_C trigger/resource update
context_builder(name='Context Builder', tags=None)
¶
Context Builder — aggregates environmental inputs into a unified observation.
Observes trigger events from the outside world (x_T) and available resources/constraints (x_C), then builds a unified observation x in X together with the feasible decision set Y' = U(x_T, x_C) ⊆ Y. Also constructs the continuation context k: Y → R that the Reactive Decision game uses to evaluate candidate actions. This is a covariant lifting — a pure function with no utility or coutility.
Source code in packages/gds-games/ogs/dsl/library.py
history(name='History', tags=None)
¶
History — accumulates past observations and decisions over time.
Maintains an append-only record of (policy, action, outcome) tuples. Initialized from h_0 and updated via the contravariant History Update port: h' = g_2(p, u, r, h) := (h, (p, u, r)). The latest history is forwarded to the Policy game so it can condition its strategy selection on past experience.
Source code in packages/gds-games/ogs/dsl/library.py
policy(name='Policy', tags=None)
¶
Policy — maps history to a strategy (policy function p ∈ P).
Selects a strategy σ: X → Y from the policy space P, conditioned on the accumulated history. Receives experience feedback (coutility) from the Reactive Decision game and uses it to update the policy: p' = g_1(h, u, r; p). Emits a History Update (coutility s) back to the History game so the record includes the latest round. Initialized from p_0 (e.g., uniform over actions).
Source code in packages/gds-games/ogs/dsl/library.py
outcome(name='Outcome', tags=None)
¶
Outcome — evaluates decisions against the external world to compute payoff.
Takes the agent's chosen action u and the external world state ¬u (the counterfactual — what would have happened under alternative actions) and computes the realized utility r = Q(u, ¬u). This outcome is fed back contravariantly to the Reactive Decision game as its resolved payoff, closing the decision-evaluation loop.
Source code in packages/gds-games/ogs/dsl/library.py
reactive_decision(name='Reactive Decision', tags=None)
¶
Reactive Decision — the core decision game where the agent chooses an action.
The central decision point. Observes the context (x, Y', k) built by the Context Builder and the current policy p from the Policy game. Selects an action y = σ(x) from the feasible set Y' ⊆ Y according to strategy σ: X → Y parameterized by policy p. Receives resolved outcome r in R (utility) from the Outcome game. Transmits experience s in S (coutility) back to the Policy game for learning. The best-response function B(x, k) identifies which strategies are rational given the continuation.
Source code in packages/gds-games/ogs/dsl/library.py
reactive_decision_agent(name='Reactive Decision Agent', include_outcome=True, include_feedback=True)
¶
reactive_decision_agent(
name: str = ...,
include_outcome: Literal[True] = ...,
include_feedback: Literal[True] = ...,
) -> FeedbackLoop
Reactive decision agent — configurable single-agent decision loop.
Builds a Reactive Decision Pattern chain from atomic games. The two boolean flags control which components are included:
+------------------+------------------+------------------------------+
| include_outcome | include_feedback | Returns |
+==================+==================+==============================+
| True (default) | True (default) | FeedbackLoop — full |
| | | 5-game loop (CB→Hist→Pol |
| | | →RD→Out + 3 feedback flows) |
+------------------+------------------+------------------------------+
| False | True | FeedbackLoop — 4-game |
| | | loop without Outcome game |
+------------------+------------------+------------------------------+
| True | False | SequentialComposition |
| | | — 5-game open chain, |
| | | no feedback wrap |
+------------------+------------------+------------------------------+
| False | False | SequentialComposition |
| | | — 4-game open-loop chain |
| | | (CB→Hist→Pol→RD), suited |
| | | for multi-agent patterns |
| | | where Outcome and feedback |
| | | are wired at pattern level |
+------------------+------------------+------------------------------+
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Base name for the agent; used as the composition/loop name and
as the domain tag on each atomic game ( |
'Reactive Decision Agent'
|
include_outcome
|
bool
|
When |
True
|
include_feedback
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
FeedbackLoop | SequentialComposition
|
|
FeedbackLoop | SequentialComposition
|
|
Source code in packages/gds-games/ogs/dsl/library.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
parallel(games, name=None)
¶
Compose a list of games in parallel.
Convenience wrapper for ParallelComposition.from_list(). Use this
when building N-agent patterns where the number of agents may vary::
agents = [
reactive_decision_agent(f"Agent {i}", include_outcome=False, include_feedback=False)
for i in range(1, n + 1)
]
agents_parallel = parallel(agents)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
games
|
list[OpenGame]
|
At least 2 |
required |
name
|
str | None
|
Optional name override. Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 games are provided. |
Source code in packages/gds-games/ogs/dsl/library.py
multi_agent_composition(agents, router, feedback_port_map, wiring=None, name=None)
¶
Compose N open-loop agents in parallel, wire them into a router, and generate all feedback flows automatically.
This helper encodes the three-step structure that every multi-agent pattern follows:
- Parallel composition — all agents run side-by-side
- Sequential composition — agents feed into the shared
router - FeedbackLoop —
N × Kcontravariant flows (one per agent per feedback channel) route the router's outputs back into each agent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agents
|
list[OpenGame]
|
Open-loop agent games (typically built with
|
required |
router
|
OpenGame
|
The shared game that receives all agent decisions and produces per-agent outcomes/feedback signals (e.g. a Decision Router). |
required |
feedback_port_map
|
dict[str, tuple[str, str]]
|
Maps a semantic label to a
Example:: |
required |
wiring
|
list[Flow] | None
|
Optional explicit |
None
|
name
|
str | None
|
Name for the resulting |
None
|
Returns:
| Type | Description |
|---|---|
FeedbackLoop
|
A |
FeedbackLoop
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 agents are provided. |
Example::
agent1 = reactive_decision_agent("Agent 1", include_outcome=False, include_feedback=False)
agent2 = reactive_decision_agent("Agent 2", include_outcome=False, include_feedback=False)
router = my_decision_router()
game = multi_agent_composition(
agents=[agent1, agent2],
router=router,
feedback_port_map={
"outcome": ("Outcome", "Outcome"),
"experience": ("Experience", "Experience"),
"history": ("History Update", "History Update"),
},
)
Source code in packages/gds-games/ogs/dsl/library.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |