The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(todos): delegate todo tool logic to TinyAgents' session_list
Steven Enamakel85684ac89f18
diff --git a/crates/openhuman-core/src/agent/todos/ops.rs b/crates/openhuman-core/src/agent/todos/ops.rsindex 22859aa3bd..c501110bbc 100644--- a/crates/openhuman-core/src/agent/todos/ops.rs+++ b/crates/openhuman-core/src/agent/todos/ops.rs@@ -1,27 +1,19 @@-//! OpenHuman host adapter over [`tinyagents_graph::todos`].+//! OpenHuman host adapter over TinyAgents' `todos::session_list`.//!//! A todo list is scoped to one agent session ([`TodoScope::Session`]) or,//! when a tool runs with no session at all, to a scratch list-//! ([`TodoScope::Scratch`]). Both live in the one in-process store; the-//! normalisation and rendering are TinyAgents'. The whole-list `replace` is-//! the only write the `todo` tool needs; `clear` is for tests and cleanup.+//! ([`TodoScope::Scratch`]). Both live in the one in-process [`store`];+//! validation, the whole-list write and rendering are TinyAgents'. This file+//! only maps a scope onto a store key. `clear` is for tests and cleanup.-use serde::{Deserialize, Serialize};-use tinyagents_graph::todos::store as todos;+use std::sync::Arc;++use tinyagents_graph::todos::session_list;+use tinyagents_harness::store::Store;use crate::agent::tinyagents::todos::{session_todos_store, SCRATCH_SESSION_ID};-use crate::agent::todos::types::normalize_cards_for_wire;pub use crate::agent::todos::types::{TaskBoardCard, TaskCardStatus};--pub use tinyagents_graph::todos::{parse_status, render_markdown};--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct TodosSnapshot {- pub session_id: Option<String>,- pub cards: Vec<TaskBoardCard>,- pub markdown: String,-}+pub use tinyagents_graph::todos::TodosSnapshot;#[derive(Debug, Clone, PartialEq, Eq)]pub enum TodoScope {@@ -37,43 +29,30 @@ impl TodoScope {}}- fn key(&self) -> &str {+ /// The store key this scope's list lives under.+ pub fn key(&self) -> &str {self.session_id().unwrap_or(SCRATCH_SESSION_ID)}}-fn snapshot(scope: &TodoScope, value: tinyagents_graph::todos::TodosSnapshot) -> TodosSnapshot {- TodosSnapshot {- session_id: scope.session_id().map(str::to_owned),- cards: value.cards,- markdown: value.markdown,- }-}--fn finish(- scope: &TodoScope,- result: tinyagents_harness::error::Result<tinyagents_graph::todos::TodosSnapshot>,-) -> Result<TodosSnapshot, String> {- let mut value = result.map_err(|error| error.to_string())?;- normalize_cards_for_wire(&mut value.cards);- Ok(snapshot(scope, value))+/// The process-wide store every session's list lives in.+pub fn store() -> Arc<dyn Store> {+ session_todos_store()}pub async fn replace(scope: &TodoScope, cards: Vec<TaskBoardCard>) -> Result<TodosSnapshot, String> {- let store = session_todos_store();- finish(scope, todos::replace(&store, scope.key(), cards).await)+ session_list::write(&store(), scope.key(), cards)+ .await+ .map_err(|error| error.to_string())}pub async fn clear(scope: &TodoScope) -> Result<TodosSnapshot, String> {- let store = session_todos_store();- finish(scope, todos::clear(&store, scope.key()).await)+ replace(scope, Vec::new()).await}pub async fn list(scope: &TodoScope) -> Result<TodosSnapshot, String> {- let store = session_todos_store();- todos::list(&store, scope.key())+ session_list::read(&store(), scope.key()).await- .map(|value| snapshot(scope, value)).map_err(|error| error.to_string())}diff --git a/crates/openhuman-core/src/agent/tools/todo.rs b/crates/openhuman-core/src/agent/tools/todo.rsindex 375cfa821f..b1fa6bb0ef 100644--- a/crates/openhuman-core/src/agent/tools/todo.rs+++ b/crates/openhuman-core/src/agent/tools/todo.rs@@ -1,25 +1,25 @@//! `todo` — the session's todo list, the way Claude Code and Codex have it.//!-//! One call writes the whole list: `{"todos": [{"content", "status"}]}`.-//! There is no per-card CRUD, no approval gate, no evidence, no plan; the-//! list is a progress checklist the model rewrites as it works. It is scoped-//! to the agent session the turn runs in (in memory, for the life of the-//! process) via [`crate::agent::todos::ops`]; without a session (a bare-//! `execute` in a test) it falls back to a scratch list. Calling with no-//! `todos` returns the current list.+//! The tool itself is TinyAgents' `todos::session_list` (schema, argument+//! validation, the whole-list write, markdown). This file is only the host+//! adapter: it decides **which** list a call is about — the agent session the+//! turn runs in, in memory for the life of the process — and registers the+//! harness dispatch. Nothing here may turn a bad argument into an `Err`: a+//! dispatch `Err` is fatal to the run, and a turn died that way when a model+//! sent the retired `{"cards": …}` shape to the previous host-side copy.use crate::agent::harness::fork_context::ParentExecutionContext;use crate::agent::todos::ops::{self, TodoScope};-use crate::agent::todos::types::{TaskBoardCard, TaskCardStatus};use async_trait::async_trait;-use serde::Deserialize;-use serde_json::json;use std::sync::Arc;+use tinyagents_graph::todos::session_list;use tinyagents_harness::context::RunContext;use tinyagents_harness::tool::{ToolDispatch, ToolExecutionContext};use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};-pub struct TodoTool;+pub struct TodoTool {+ inner: session_list::SessionTodoTool,+}pub(crate) struct TodoToolDispatch {tool: Arc<dyn Tool>,@@ -43,11 +43,6 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Tparent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,) -> anyhow::Result<ToolResult> {let context = ToolExecutionContext::from_run_context(parent, _call_id.clone());- // A dispatch `Err` is fatal to the whole run in the harness- // ("canonical execution errors remain fatal"), so nothing about a bad- // argument may escape as one: it goes back to the model as a tool- // error it can correct. A turn died this way when a model sent the- // retired `{"cards": …}` shape.match TodoTool::new().execute_with_parent_context(arguments, parent.data.parent.clone(), Some(&context)).await@@ -63,7 +58,9 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Timpl TodoTool {pub fn new() -> Self {- Self+ Self {+ inner: session_list::SessionTodoTool::new(ops::store()),+ }}}@@ -73,50 +70,18 @@ impl Default for TodoTool {}}-/// One item as the model writes it. `status` accepts the Claude-style-/// `pending` / `in_progress` / `completed` plus the older `todo` / `done`-/// spellings the store already parses.-#[derive(Deserialize)]-struct TodoItem {- content: String,- #[serde(default)]- status: Option<String>,-}-#[async_trait]impl Tool for TodoTool {fn name(&self) -> &str {- "todo"+ self.inner.name()}fn description(&self) -> &str {- "Your todo list for this conversation. Pass the complete list every time; it \- replaces what was there. Use it for work with 3+ steps: write the steps up front, \- keep exactly one `in_progress`, mark each `completed` the moment it is done. Omit \- `todos` to read the current list."+ self.inner.description()}fn parameters_schema(&self) -> serde_json::Value {- json!({- "type": "object",- "properties": {- "todos": {- "type": "array",- "description": "The full list, in order.",- "items": {- "type": "object",- "properties": {- "content": { "type": "string" },- "status": {- "type": "string",- "enum": ["pending", "in_progress", "completed"]- }- },- "required": ["content", "status"]- }- }- }- })+ self.inner.parameters_schema()}fn permission_level(&self) -> PermissionLevel {@@ -148,80 +113,7 @@ impl TodoTool {) -> anyhow::Result<ToolResult> {let scope = current_scope(parent.as_ref(), tool_context);tracing::debug!(session_id = ?scope.session_id(), "[tool][todo] dispatch");-- let result = match args.get("todos") {- None | Some(serde_json::Value::Null) => match args.as_object() {- // A write that used some other key (`cards`, `items`, …) is a- // shape error to report, not a request to read the list.- Some(map) if !map.is_empty() => Err(format!(- "unknown arguments {:?}: pass `todos` (the full list of \- {{content, status}}), or no arguments to read the list",- map.keys().collect::<Vec<_>>()- )),- _ => ops::list(&scope).await,- },- Some(raw) => match parse_items(raw) {- Ok(cards) => ops::replace(&scope, cards).await,- Err(error) => Err(error),- },- };-- match result {- Ok(snap) => {- let todos: Vec<serde_json::Value> = snap- .cards- .iter()- .map(|card| {- json!({- "content": card.title,- "status": wire_status(card.status),- })- })- .collect();- let payload = json!({- "sessionId": snap.session_id,- "todos": todos,- "markdown": snap.markdown,- });- Ok(ToolResult::success(payload.to_string()))- }- Err(err) => Ok(ToolResult::error(err)),- }- }-}--/// Turn the model's `todos` array into store cards; every problem is a-/// message for the model, never a harness error.-fn parse_items(raw: &serde_json::Value) -> Result<Vec<TaskBoardCard>, String> {- let items: Vec<TodoItem> =- serde_json::from_value(raw.clone()).map_err(|e| format!("invalid `todos`: {e}"))?;- let mut cards = Vec::with_capacity(items.len());- for item in items {- let content = item.content.trim();- if content.is_empty() {- return Err("every todo needs non-empty `content`".to_string());- }- let mut card = TaskBoardCard::new(content);- card.status = match item.status.as_deref() {- None => TaskCardStatus::Todo,- Some(raw) => ops::parse_status(raw)?,- };- cards.push(card);- }- Ok(cards)-}--/// The three states the model is told about. Store states the list can no-/// longer produce (`ready`, `awaiting_approval`, `rejected`, `blocked`) fold-/// into the nearest one so an old thread still reads sensibly.-fn wire_status(status: TaskCardStatus) -> &'static str {- match status {- TaskCardStatus::InProgress => "in_progress",- TaskCardStatus::Done | TaskCardStatus::Rejected => "completed",- TaskCardStatus::Todo- | TaskCardStatus::Ready- | TaskCardStatus::AwaitingApproval- | TaskCardStatus::Blocked => "pending",+ Ok(session_list::call(&ops::store(), scope.key(), &args).await?)}}