Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions crates/ironclaw_engine/orchestrator/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,43 @@ def format_docs(docs):
return "\n".join(parts)


def ensure_working_messages(state, context):
"""Initialize the mutable orchestrator transcript."""
existing = state.get("working_messages")
if isinstance(existing, list):
return existing
if isinstance(context, list):
state["working_messages"] = list(context)
else:
state["working_messages"] = []
return state["working_messages"]


def append_message(messages, role, content, action_name=None, action_call_id=None, action_calls=None):
"""Append a normalized message to the working transcript."""
msg = {"role": role, "content": content}
if action_name is not None:
msg["action_name"] = action_name
if action_call_id is not None:
msg["action_call_id"] = action_call_id
if action_calls is not None:
msg["action_calls"] = action_calls
messages.append(msg)


def append_system_append(messages, content):
"""Append additional context to the first system message."""
for msg in messages:
if msg.get("role") == "System":
existing = msg.get("content", "")
if existing:
msg["content"] = existing + "\n\n" + content
else:
msg["content"] = content
return
messages.insert(0, {"role": "System", "content": content})


# Conservative fallback heuristic matching the old Rust-side estimator.
# These MUST be defined before `estimate_context_tokens` (and therefore
# before the `FINAL(result)` entry-point call below). Moving them after the
Expand Down Expand Up @@ -650,43 +687,6 @@ def format_skills(skills):
return "\n".join(parts)


def ensure_working_messages(state, context):
"""Initialize the mutable orchestrator transcript."""
existing = state.get("working_messages")
if isinstance(existing, list):
return existing
if isinstance(context, list):
state["working_messages"] = list(context)
else:
state["working_messages"] = []
return state["working_messages"]


def append_message(messages, role, content, action_name=None, action_call_id=None, action_calls=None):
"""Append a normalized message to the working transcript."""
msg = {"role": role, "content": content}
if action_name is not None:
msg["action_name"] = action_name
if action_call_id is not None:
msg["action_call_id"] = action_call_id
if action_calls is not None:
msg["action_calls"] = action_calls
messages.append(msg)


def append_system_append(messages, content):
"""Append additional context to the first system message."""
for msg in messages:
if msg.get("role") == "System":
existing = msg.get("content", "")
if existing:
msg["content"] = existing + "\n\n" + content
else:
msg["content"] = content
return
messages.insert(0, {"role": "System", "content": content})


def complete_result(state, outcome, response=None, error=None, extra=None):
"""Return a standard orchestrator result with persisted state."""
result = {"outcome": outcome, "state": state}
Expand Down
1 change: 1 addition & 0 deletions crates/ironclaw_engine/src/capability/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ mod tests {
parameters_schema: serde_json::json!({}),
effects,
requires_approval,
discovery: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/ironclaw_engine/src/capability/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ mod tests {
parameters_schema: serde_json::json!({}),
effects,
requires_approval,
discovery: None,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/ironclaw_engine/src/capability/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ mod tests {
parameters_schema: serde_json::json!({"type": "object"}),
effects: vec![EffectType::WriteExternal, EffectType::CredentialedNetwork],
requires_approval: false,
discovery: None,
},
ActionDef {
name: "list_prs".into(),
description: "List pull requests".into(),
parameters_schema: serde_json::json!({"type": "object"}),
effects: vec![EffectType::ReadExternal, EffectType::CredentialedNetwork],
requires_approval: false,
discovery: None,
},
],
knowledge: vec!["When creating issues, always add labels.".into()],
Expand Down Expand Up @@ -144,6 +146,7 @@ mod tests {
parameters_schema: serde_json::json!({"type": "object"}),
effects: vec![EffectType::ReadLocal],
requires_approval: false,
discovery: None,
}],
knowledge: vec![],
policies: vec![],
Expand Down
6 changes: 6 additions & 0 deletions crates/ironclaw_engine/src/executor/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ mod tests {
source_channel: None,
user_timezone: None,
thread_goal: Some("search the web".into()),
available_actions_snapshot: None,
available_action_inventory_snapshot: None,
},
)
.await
Expand Down Expand Up @@ -220,6 +222,8 @@ mod tests {
source_channel: None,
user_timezone: None,
thread_goal: Some("hello".into()),
available_actions_snapshot: None,
available_action_inventory_snapshot: None,
},
)
.await
Expand Down Expand Up @@ -254,6 +258,8 @@ mod tests {
source_channel: None,
user_timezone: None,
thread_goal: Some("hello".into()),
available_actions_snapshot: None,
available_action_inventory_snapshot: None,
},
)
.await
Expand Down
Loading
Loading