Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(goals): add goal_to_value helper for serializing ThreadGoal

Steven Enamakel7f53427ff68d
diff --git a/crates/openhuman-core/src/agent/goals/mod.rs b/crates/openhuman-core/src/agent/goals/mod.rs
index 5ffe8bee68..062bfe3a65 100644
--- a/crates/openhuman-core/src/agent/goals/mod.rs
+++ b/crates/openhuman-core/src/agent/goals/mod.rs
@@ -13,3 +13,13 @@ pub mod tools;
pub use tinyagents_graph::goals::{ThreadGoal, ThreadGoalStatus};
pub use tools::{GoalCompleteTool, GoalGetTool, GoalSetTool};
+
+/// Serialize a [`ThreadGoal`] for the `goal` field on `ThreadGoalUpdated` /
+/// `threads.goal_get`. `ThreadGoal` is owned by `tinyagents-graph`, so this is
+/// kept as a raw `Value` rather than a typed field on the event. Falls back to
+/// `Value::Null` on an (unexpected) serialization failure rather than
+/// panicking or dropping the event.
+#[must_use]
+pub fn goal_to_value(goal: &ThreadGoal) -> serde_json::Value {
+ serde_json::to_value(goal).unwrap_or(serde_json::Value::Null)
+}