|
439 | 439 |
|
440 | 440 |
|
441 | 441 | def v0_capability_catalog() -> str: |
442 | | - """Create the Capability Catalog system block. |
443 | | -
|
444 | | - Lists every available action set and every enabled skill with a |
445 | | - one-line description, so any session can discover and load |
446 | | - capabilities on demand (add_action_sets / use_skill). The catalog |
447 | | - is stable per boot, so it lives in the cached system prefix. |
448 | | - """ |
449 | | - lines = ["<capability_catalog>"] |
450 | | - |
451 | | - try: |
452 | | - from app.action.action_set import action_set_manager |
453 | | - |
454 | | - sets_text = _v0_format_sets(action_set_manager, exclude_core=True) |
455 | | - lines.append( |
456 | | - "Action sets you can load with 'add_action_sets' " |
457 | | - "(your session always has 'core'):" |
458 | | - ) |
459 | | - lines.append(sets_text if sets_text else "(no additional action sets)") |
460 | | - except Exception as e: |
461 | | - _logger.debug(f"[CONTEXT] Capability catalog: action sets failed: {e}") |
462 | | - |
463 | | - try: |
464 | | - from app.skill import skill_manager |
465 | | - |
466 | | - skills = skill_manager.list_skills_for_selection() |
467 | | - lines.append("") |
468 | | - lines.append("Skills you can load with 'use_skill':") |
469 | | - if skills: |
470 | | - lines.extend(f"- {name}: {desc}" for name, desc in skills.items()) |
471 | | - else: |
472 | | - lines.append("(no skills available)") |
473 | | - except Exception as e: |
474 | | - _logger.debug(f"[CONTEXT] Capability catalog: skills failed: {e}") |
475 | | - |
476 | | - lines.append("</capability_catalog>") |
477 | | - return "\n".join(lines) |
| 442 | + """Create the Capability Catalog system block. |
| 443 | +
|
| 444 | + Lists every available action set and every enabled skill with a |
| 445 | + one-line description, so any session can discover and load |
| 446 | + capabilities on demand (add_action_sets / use_skill). The catalog |
| 447 | + is stable per boot, so it lives in the cached system prefix. |
| 448 | + """ |
| 449 | + lines = ["<capability_catalog>"] |
| 450 | + |
| 451 | + try: |
| 452 | + from app.action.action_set import action_set_manager |
| 453 | + |
| 454 | + sets_text = _v0_format_sets(action_set_manager, exclude_core=True) |
| 455 | + lines.append( |
| 456 | + "Action sets you can load with 'add_action_sets' " |
| 457 | + "(your session always has 'core'):" |
| 458 | + ) |
| 459 | + lines.append(sets_text if sets_text else "(no additional action sets)") |
| 460 | + except Exception as e: |
| 461 | + _logger.debug(f"[CONTEXT] Capability catalog: action sets failed: {e}") |
| 462 | + |
| 463 | + try: |
| 464 | + from app.skill import skill_manager |
| 465 | + |
| 466 | + skills = skill_manager.list_skills_for_selection() |
| 467 | + lines.append("") |
| 468 | + lines.append("Skills you can load with 'use_skill':") |
| 469 | + if skills: |
| 470 | + lines.extend(f"- {name}: {desc}" for name, desc in skills.items()) |
| 471 | + else: |
| 472 | + lines.append("(no skills available)") |
| 473 | + except Exception as e: |
| 474 | + _logger.debug(f"[CONTEXT] Capability catalog: skills failed: {e}") |
| 475 | + |
| 476 | + lines.append("</capability_catalog>") |
| 477 | + return "\n".join(lines) |
478 | 478 |
|
479 | 479 |
|
480 | 480 | def _v0_format_sets(manager, exclude_core: bool = False) -> str: |
481 | | - """ |
482 | | - Format action set information for inclusion in prompts. |
483 | | -
|
484 | | - Args: |
485 | | - exclude_core: If True, don't include core set (it's always auto-included) |
486 | | -
|
487 | | - Returns: |
488 | | - Formatted string describing available action sets: one line per |
489 | | - set, then one line per integration naming all of its sets |
490 | | - (described once, by the integration's provider). Sorted, so the |
491 | | - catalog (part of the cached system prompt) renders the same on |
492 | | - every boot. |
493 | | - """ |
494 | | - all_sets = manager.list_all_sets() |
495 | | - integrations = { |
496 | | - integration: [s for s in sets if s in all_sets] |
497 | | - for integration, sets in manager.integration_sets().items() |
498 | | - } |
499 | | - owned = {s for sets in integrations.values() for s in sets} |
500 | | - |
501 | | - lines = [] |
502 | | - for set_name, description in sorted(all_sets.items()): |
503 | | - if set_name in owned or (exclude_core and set_name == "core"): |
504 | | - continue |
505 | | - if set_name == "core": |
506 | | - lines.append(f"- {set_name}: {description} (always included)") |
507 | | - else: |
508 | | - lines.append(f"- {set_name}: {description}") |
509 | | - |
510 | | - rows = [] |
511 | | - for integration, sets in integrations.items(): |
512 | | - if not sets: |
513 | | - continue |
514 | | - name, what = manager.integration_description(integration) |
515 | | - # The set named after the integration first: its high-value actions. |
516 | | - ordered = sorted(sets, key=lambda s: (s != integration, s)) |
517 | | - label = f"{name} ({what})" if what else name |
518 | | - rows.append((name.lower(), f"- {label}: {', '.join(ordered)}")) |
519 | | - if rows: |
520 | | - lines.append( |
521 | | - "Integration action sets. Load the set named after an " |
522 | | - "integration for its high-value actions; load a narrower set " |
523 | | - "when the task needs a specific area:" |
524 | | - ) |
525 | | - lines.extend(row for _, row in sorted(rows)) |
526 | | - return "\n".join(lines) |
| 481 | + """ |
| 482 | + Format action set information for inclusion in prompts. |
| 483 | +
|
| 484 | + Args: |
| 485 | + exclude_core: If True, don't include core set (it's always auto-included) |
| 486 | +
|
| 487 | + Returns: |
| 488 | + Formatted string describing available action sets: one line per |
| 489 | + set, then one line per integration naming all of its sets |
| 490 | + (described once, by the integration's provider). Sorted, so the |
| 491 | + catalog (part of the cached system prompt) renders the same on |
| 492 | + every boot. |
| 493 | + """ |
| 494 | + all_sets = manager.list_all_sets() |
| 495 | + integrations = { |
| 496 | + integration: [s for s in sets if s in all_sets] |
| 497 | + for integration, sets in manager.integration_sets().items() |
| 498 | + } |
| 499 | + owned = {s for sets in integrations.values() for s in sets} |
| 500 | + |
| 501 | + lines = [] |
| 502 | + for set_name, description in sorted(all_sets.items()): |
| 503 | + if set_name in owned or (exclude_core and set_name == "core"): |
| 504 | + continue |
| 505 | + if set_name == "core": |
| 506 | + lines.append(f"- {set_name}: {description} (always included)") |
| 507 | + else: |
| 508 | + lines.append(f"- {set_name}: {description}") |
| 509 | + |
| 510 | + rows = [] |
| 511 | + for integration, sets in integrations.items(): |
| 512 | + if not sets: |
| 513 | + continue |
| 514 | + name, what = manager.integration_description(integration) |
| 515 | + # The set named after the integration first: its high-value actions. |
| 516 | + ordered = sorted(sets, key=lambda s: (s != integration, s)) |
| 517 | + label = f"{name} ({what})" if what else name |
| 518 | + rows.append((name.lower(), f"- {label}: {', '.join(ordered)}")) |
| 519 | + if rows: |
| 520 | + lines.append( |
| 521 | + "Integration action sets. Load the set named after an " |
| 522 | + "integration for its high-value actions; load a narrower set " |
| 523 | + "when the task needs a specific area:" |
| 524 | + ) |
| 525 | + lines.extend(row for _, row in sorted(rows)) |
| 526 | + return "\n".join(lines) |
0 commit comments