Skip to content

Commit 2513ddd

Browse files
committed
feat(agents/cortex): enhance cortex agent with surprisal and g-score integration
adds surprisal tracking to main workflow, integrates g-score and expectation handling in categorization phase, and enhances reason phase with improved output structure including surprisal metrics
1 parent 272a4ba commit 2513ddd

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

src/workflows_mcp/templates/agents/cortex/main.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,12 @@ blocks:
11531153
parent_id: "{{ get(blocks.register.outputs, 'rows.0.id', '') }}"
11541154
features: "{{ inputs.features }}"
11551155
expectation_id: "{{ blocks.categorize.outputs.expectation_id | default('') }}"
1156-
surprisal: {}
1156+
surprisal:
1157+
surprisal_bits: 0
1158+
interpretation: "expected"
1159+
processing_path: "system1"
1160+
matched_prediction: true
1161+
note: "System 1 fast path - no deep prediction comparison performed"
11571162
context_hash: "{{ blocks.categorize.outputs.context_hash | default('') }}"
11581163
category: "{{ blocks.categorize.outputs.result.category | default('understanding') }}"
11591164
actions_taken: []

src/workflows_mcp/templates/agents/cortex/phases/1.categorize.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,14 @@ blocks:
782782
required: true
783783
- block: self_recurse
784784
required: false
785+
- block: form_expectation
786+
required: false
787+
- block: store_expectation
788+
required: false
789+
- block: compute_g_score
790+
required: false
791+
- block: query_heuristics
792+
required: false
785793
condition: "{{ blocks.register_phase.succeeded }}"
786794
inputs:
787795
engine: sqlite
@@ -792,7 +800,19 @@ blocks:
792800
id: "{{ get(blocks.register_phase.outputs, 'rows.0.id', '') }}"
793801
data:
794802
status: done
795-
outputs: "{'recursed': {{ blocks.self_recurse.succeeded }}, 'category': {{ get(blocks.attempt.outputs.response.result,'category','understanding') }}}"
803+
outputs: |
804+
{{
805+
{
806+
'recursed': blocks.self_recurse.succeeded,
807+
'category': get(blocks.attempt.outputs.response.result, 'category', 'understanding'),
808+
'g_score': get(blocks.compute_g_score.outputs.stdout, 'g_score', 25) if blocks.compute_g_score.succeeded else 25,
809+
'processing_path': get(blocks.compute_g_score.outputs.stdout, 'processing_path', 'system2') if blocks.compute_g_score.succeeded else 'system2',
810+
'expectation_id': get(blocks.store_expectation.outputs, 'rows.0.id', '') if blocks.store_expectation.succeeded else '',
811+
'context_hash': get(blocks.form_expectation.outputs.stdout, 'context_hash', '') if blocks.form_expectation.succeeded else '',
812+
'heuristics_count': blocks.query_heuristics.outputs.count if blocks.query_heuristics.succeeded else 0,
813+
'routing': blocks.compute_g_score.outputs.stdout if blocks.compute_g_score.succeeded else {}
814+
} | tojson
815+
}}
796816
797817
outputs:
798818
result:

src/workflows_mcp/templates/agents/cortex/phases/4.reason.yaml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ blocks:
548548
state: "{{ inputs.state }}"
549549
models: "{{ inputs.models }}"
550550
expectation_id: "{{ inputs.expectation_id }}"
551-
actual_outcome: "{{ blocks.determine_outcome.outputs.stdout }}"
551+
actual_outcome: "{{ blocks.determine_outcome.outputs.stdout | fromjson }}"
552552
context_hash: "{{ inputs.context_hash }}"
553553

554554
- id: track_done
@@ -575,17 +575,18 @@ blocks:
575575
data:
576576
status: "{{ 'done' if blocks.attempt.succeeded else 'failed' }}"
577577
outputs: |
578-
{
579-
'goal': {{ get(inputs.pipeline_config, 'reason.goal', 'explain') }},
580-
'success': {{ blocks.attempt.succeeded }},
581-
'had_execution_results': {{ get(inputs.context, 'execution_result.executed', false) }},
582-
'facts_stored': {{ get(blocks.store_facts.metadata, 'count', 0) }},
583-
{% if blocks.log_ungrounded.succeeded %}
584-
'ungrounded_findings': {{ get(blocks.log_ungrounded.outputs.stdout, 'ungrounded_count', 0) }}
585-
{% else %}
586-
'ungrounded_findings': 0
587-
{% endif %}
588-
}
578+
{{
579+
{
580+
'goal': get(inputs.pipeline_config, 'reason.goal', 'explain'),
581+
'success': blocks.attempt.succeeded,
582+
'had_execution_results': get(inputs.context, 'execution_result.executed', false),
583+
'facts_stored': get(blocks.store_facts.metadata, 'count', 0),
584+
'ungrounded_findings': get(blocks.log_ungrounded.outputs.stdout, 'ungrounded_count', 0) if blocks.log_ungrounded.succeeded else 0,
585+
'surprisal_bits': blocks.compute_surprisal.outputs.surprisal_bits if blocks.compute_surprisal.succeeded else 0,
586+
'trigger_diagnose': blocks.compute_surprisal.outputs.trigger_diagnose if blocks.compute_surprisal.succeeded else false,
587+
'matched_prediction': blocks.compute_surprisal.outputs.matched if blocks.compute_surprisal.succeeded else none
588+
} | tojson
589+
}}
589590
590591
outputs:
591592
synthesis:

0 commit comments

Comments
 (0)