Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a7e7487
feat(memory): take the memory block render off the turn's critical path
senamakel Nov 7, 2026
17f2af8
Merge pull request #708 from senamakel/epic-712-oh707-memory-block
senamakel Nov 7, 2026
0b19ca5
chore(deps): bump tinyagents to the epic-712 tool-tokens tip
senamakel Nov 7, 2026
75270be
feat(tool-search): per-session discovery options, pinned on the thread
senamakel Nov 7, 2026
d616379
Merge pull request #710 from senamakel/epic-712-oh705-bump-tinyagents
senamakel Nov 7, 2026
f76b2a9
chore(deps): bump tinyagents and tinysearch to the epic-712 tool-toke…
senamakel Nov 7, 2026
fa2febb
fix(memory): apply the turn's route and model overrides when prewarmi…
senamakel Nov 7, 2026
13069ac
Merge pull request #712 from senamakel/epic-712-oh709-prewarm-overrides
senamakel Nov 7, 2026
4772736
feat(context): per-session keep_recent_tokens, result expiry, reasoni…
senamakel Nov 7, 2026
714a3bf
feat(search): compact result rendering and a page-contents cap
senamakel Nov 7, 2026
aa067f4
docs(embed): regenerate the embed API docs and describe the search re…
senamakel Nov 7, 2026
44dbae5
test(session): the codec records replay options on the first new row …
senamakel Nov 7, 2026
b2fec98
Merge the epic-712 tool-tokens tip into the 706 bump branch
senamakel Nov 7, 2026
17ecf3b
Merge pull request #714 from senamakel/epic-712-oh706-bump-options
senamakel Nov 8, 2026
ba2a32a
chore(deps): bump vendor/tinyagents to the epic-712 tip with TurnObse…
senamakel Nov 8, 2026
22df2f6
fix(tool-output): exempt tool_search results from TinyJuice reshaping
senamakel Nov 8, 2026
abc2c67
fix(session): carry the tool_discovery pin into a compacted generation
senamakel Nov 8, 2026
231fcaa
feat(embed): force tool_search options onto an existing thread
senamakel Nov 8, 2026
16d28f1
Merge pull request #715 from senamakel/tool-search-followups
senamakel Nov 8, 2026
fae7aaa
feat(observe): report turn-setup phases through TurnObservation::Setup
senamakel Nov 8, 2026
9f6fee3
Merge the epic-712 tool-tokens tip into the 713 setup-phases branch
senamakel Nov 8, 2026
d1bec9e
docs(embed): describe the setup observations in OBSERVERS.md
senamakel Nov 8, 2026
c1e9994
fix(session): carry the context replay pin into a compacted generation
senamakel Nov 8, 2026
36665cf
Merge pull request #717 from senamakel/replay-pin-compaction
senamakel Nov 8, 2026
f089bcf
Merge the epic-712 tool-tokens tip into the 713 setup-phases branch
senamakel Nov 8, 2026
d4108d0
Merge pull request #718 from senamakel/epic-712-713-setup-phases
senamakel Nov 8, 2026
d1877f9
fix(session): keep a recorded replay pin on a generation-start turn
senamakel Nov 8, 2026
31abfcf
Merge fork/epic/712-tool-tokens into replay-pin-resolve-guard
senamakel Nov 8, 2026
4c41207
Merge pull request #719 from senamakel/replay-pin-resolve-guard
senamakel Nov 8, 2026
227862e
fix(session): hand the session's expiry, reasoning-replay and discove…
senamakel Nov 8, 2026
345c639
Merge pull request #721 from senamakel/epic-712-720-expiry-run-loop
senamakel Nov 8, 2026
cc851ea
Merge remote-tracking branch 'origin/main' into epic-712-upstream-merge
senamakel Nov 8, 2026
7b39bef
fix(ci): satisfy rust-layout, process-statics and runtime-boundary gu…
senamakel Nov 8, 2026
58aea38
Merge pull request #722 from senamakel/epic-712-ci-guards
senamakel Nov 8, 2026
b3a6f13
docs(embed): link memory_block_deadline to Agent::prewarm_memory_bloc…
senamakel Nov 8, 2026
4389c0b
chore(deps): bump vendor/tinysearch to 111a9526
senamakel Nov 8, 2026
caa32b6
chore(deps): point vendor/tinyagents and vendor/tinysearch at their u…
senamakel Nov 8, 2026
33cea3a
chore(modules): re-pin tinysearch to 0.5.7
senamakel Nov 8, 2026
7932f10
chore(deps): refresh Cargo.lock for tinysearch 0.5.7
senamakel Nov 8, 2026
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/openhuman-core/src/agent/context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ No `store.rs`. State is per-session and in-memory:

## Dependencies

- `crate::config`: `ContextSettings` ([`config/schema/context.rs`](../../config/schema/context.rs)), the whole `[context]` table: TinyAgents' `ContextConfig` flattened (reached through `Deref`, so `config.context.<field>` reads it) plus OpenHuman's `summarizer_tool_rendering` (`full` | `markers`; env `OPENHUMAN_CONTEXT_SUMMARIZER_TOOL_RENDERING`: `markers` sends the summarizer one `[used <tool>: …]` line per call and no tool results, for small summarization models) and `summarizer_max_output_tokens` (env `OPENHUMAN_CONTEXT_SUMMARIZER_MAX_OUTPUT_TOKENS`, `0` clears: the summary request's `max_tokens`). The free-form (`summary`) strategy applies both; `task_state` ignores them. `ContextConfig`: `enabled`, `microcompact_enabled` / `microcompact_keep_recent`, `autocompact_enabled`, `compaction_trigger_tokens` (absolute summarization trigger for benchmarks; env `OPENHUMAN_COMPACTION_TRIGGER_TOKENS`), `compaction_strategy` (env `OPENHUMAN_COMPACTION_STRATEGY`), `compaction_enabled`, `tool_result_budget_bytes`, `prefer_markdown_tool_output`, `summarizer_model` (env `OPENHUMAN_CONTEXT_SUMMARIZER_MODEL`: the model the compaction summarizer calls on the turn's own provider route; unset or blank uses the turn's model), and the embedded `session_memory: SessionMemoryConfig`.
- `crate::config`: `ContextSettings` ([`config/schema/context.rs`](../../config/schema/context.rs)), the whole `[context]` table: TinyAgents' `ContextConfig` flattened (reached through `Deref`, so `config.context.<field>` reads it) plus OpenHuman's `keep_recent_tokens` (env `OPENHUMAN_CONTEXT_KEEP_RECENT_TOKENS`, `0` clears: the verbatim tail an in-turn compaction keeps; unset keeps 20,000, capped at a fifth of a known context window; an embedder sets it per agent or turn with `AgentSpec::keep_recent_tokens` / `Turn::keep_recent_tokens`), `tool_result_max_age_turns` (env `OPENHUMAN_CONTEXT_TOOL_RESULT_MAX_AGE_TURNS`; unset or `0` keeps every tool result, a number replaces a result older than that many user turns with a one-line note) with `tool_result_exempt_tools` (env `OPENHUMAN_CONTEXT_TOOL_RESULT_EXEMPT_TOOLS`, comma separated), `replay_reasoning` (`all` | `current_turn`, env `OPENHUMAN_CONTEXT_REPLAY_REASONING`; `current_turn` leaves earlier turns' reasoning out of the request, the stored transcript keeps it), `prune_retired_tools` (env `OPENHUMAN_CONTEXT_PRUNE_RETIRED_TOOLS`; drops a recorded tool declaration the host no longer offers, live or deferred, instead of carrying it for the life of the thread), and `summarizer_tool_rendering` (`full` | `markers`; env `OPENHUMAN_CONTEXT_SUMMARIZER_TOOL_RENDERING`: `markers` sends the summarizer one `[used <tool>: …]` line per call and no tool results, for small summarization models) and `summarizer_max_output_tokens` (env `OPENHUMAN_CONTEXT_SUMMARIZER_MAX_OUTPUT_TOKENS`, `0` clears: the summary request's `max_tokens`). The free-form (`summary`) strategy applies the two summarizer keys; `task_state` ignores them. The expiry and reasoning-replay keys change the bytes of every later prompt, so a session pins them on a thread when it creates it (`agent/tinyagents/replay_pin.rs`, recorded as `context_replay` on the first transcript row beside `tool_discovery`) and a resumed thread keeps them whatever the config says now; a thread that recorded nothing keeps today's behaviour. `ContextConfig`: `enabled`, `microcompact_enabled` / `microcompact_keep_recent`, `autocompact_enabled`, `compaction_trigger_tokens` (absolute summarization trigger for benchmarks; env `OPENHUMAN_COMPACTION_TRIGGER_TOKENS`), `compaction_strategy` (env `OPENHUMAN_COMPACTION_STRATEGY`), `compaction_enabled`, `tool_result_budget_bytes`, `prefer_markdown_tool_output`, `summarizer_model` (env `OPENHUMAN_CONTEXT_SUMMARIZER_MODEL`: the model the compaction summarizer calls on the turn's own provider route; unset or blank uses the turn's model), and the embedded `session_memory: SessionMemoryConfig`.
- `crate::inference::provider::UsageInfo`: fed into `record_usage`.
- `crate::agent::prompts`: owns prompt rendering; `channels_prompt.rs` uses `inject_inline_content`.
- `crate::skills::Workflow`: `channels_prompt.rs` renders the available-skills section from a `&[Workflow]`.
Expand Down
4 changes: 2 additions & 2 deletions crates/openhuman-core/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ pub(crate) mod turn_policy;
pub(crate) mod turn_progress;
#[allow(unused_imports)]
pub use session_host::{
CompactOptions, CompactOutcome, HostTools, HostTurnTools, OpenHumanSessionHost,
SessionHostBuilder, TurnContext, TurnOverrides,
CompactOptions, CompactOutcome, HostTools, HostTurnTools, MemoryBlockPrewarm,
OpenHumanSessionHost, SessionHostBuilder, TurnContext, TurnOverrides,
};
17 changes: 17 additions & 0 deletions crates/openhuman-core/src/agent/session_host/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ impl TranscriptCodec<OpenHumanRunContext> for OpenHumanTranscriptCodec {
});
}
}
// The turn that starts a thread writes down the discovery options it
// runs with, so every later turn reads them back instead of the config.
if let Some(options) = sidecar.discovery_record {
options.record_on(&mut reconciled.rows, &reconciled.fresh);
Comment thread
senamakel marked this conversation as resolved.
Resolved
}
// A compaction writes the retained rows into a new generation, and the
// stored row that carried the record may not be among them (a
// refreshed system prompt, a summary). Carry the thread's options onto
// the new generation's first row. An ordinary turn keeps the row that
// holds them, so this does nothing there. Out-of-band compaction
// (`compact_bound_history`) and an in-turn one both come through here.
crate::agent::tinyagents::discovery::carry_forward(&prior, &mut reconciled.rows);
Comment thread
senamakel marked this conversation as resolved.
Resolved
// Likewise the history-replay options (result expiry, reasoning replay).
if let Some(options) = &sidecar.replay_record {
options.record_on(&mut reconciled.rows, &reconciled.fresh);
}
crate::agent::tinyagents::replay_pin::carry_forward(&prior, &mut reconciled.rows);
attach_text_dialect_rounds(
&mut reconciled.rows,
&reconciled.fresh,
Expand Down
215 changes: 215 additions & 0 deletions crates/openhuman-core/src/agent/session_host/codec_adoption_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,218 @@ fn failed_tool_outcome_does_not_mark_an_earlier_turns_result_with_the_same_call_
);
assert!(rows[3].tool_failure.as_ref().is_some_and(|f| f.failed));
}

/// The turn that starts a thread records its discovery options on the first
/// row it writes; the turns after it neither add nor move the record.
#[test]
fn the_codec_records_discovery_options_on_the_first_new_row_only_once() {
use crate::agent::tinyagents::discovery::DiscoveryOptions;

let options = |context| TranscriptTurnOptions {
request_id: Some("turn".into()),
thread_id: None,
stream: false,
resume: ResumeMode::Never,
context,
};
let wanted = DiscoveryOptions {
promote_found_tools: false,
..DiscoveryOptions::TODAY
};
let context = OpenHumanRunContext::new();
context.session_sidecar.lock().unwrap().discovery_record = Some(wanted);
let first = vec![Message::system("prompt"), Message::user("one")];
let prior = OpenHumanTranscriptCodec
.reconcile(&[], &[], &first, &options(context))
.unwrap();
assert_eq!(DiscoveryOptions::recorded_in(&prior), Some(wanted));
assert!(prior[1].extra_metadata.is_none());

// A later turn records nothing and leaves the stored row as it was.
let mut next = first.clone();
next.push(Message::assistant("done"));
let rows = OpenHumanTranscriptCodec
.reconcile(&prior, &first, &next, &options(OpenHumanRunContext::new()))
.unwrap();
assert_eq!(rows[0], prior[0]);
assert_eq!(DiscoveryOptions::recorded_in(&rows), Some(wanted));
}

/// The turn that starts a thread records its history-replay options on the
/// first row it writes, beside any discovery record; later turns neither add
/// nor move it.
#[test]
fn the_codec_records_replay_options_on_the_first_new_row_only_once() {
use crate::agent::tinyagents::replay_pin::ReplayOptions;
use tinyagents_harness::reasoning_replay::ReasoningReplay;

let options = |context| TranscriptTurnOptions {
request_id: Some("turn".into()),
thread_id: None,
stream: false,
resume: ResumeMode::Never,
context,
};
let wanted = ReplayOptions {
tool_result_max_age_turns: Some(6),
tool_result_exempt_tools: vec!["tool_search".into()],
replay_reasoning: ReasoningReplay::CurrentTurn,
};
let context = OpenHumanRunContext::new();
context.session_sidecar.lock().unwrap().replay_record = Some(wanted.clone());
let first = vec![Message::system("prompt"), Message::user("one")];
let prior = OpenHumanTranscriptCodec
.reconcile(&[], &[], &first, &options(context))
.unwrap();
assert_eq!(ReplayOptions::recorded_in(&prior), Some(wanted.clone()));
assert!(prior[1].extra_metadata.is_none());

// A later turn records nothing and leaves the stored row as it was.
let mut next = first.clone();
next.push(Message::assistant("done"));
let rows = OpenHumanTranscriptCodec
.reconcile(&prior, &first, &next, &options(OpenHumanRunContext::new()))
.unwrap();
assert_eq!(rows[0], prior[0]);
assert_eq!(ReplayOptions::recorded_in(&rows), Some(wanted));
}

/// A compaction writes the retained rows into a new generation. Its first row
/// is the refreshed system prompt, so the stored row that carried the
/// discovery record is gone; the codec records it again.
#[test]
fn discovery_pin_survives_compaction() {
use crate::agent::tinyagents::discovery::DiscoveryOptions;

let options = |context| TranscriptTurnOptions {
request_id: Some("turn".into()),
thread_id: None,
stream: false,
resume: ResumeMode::Never,
context,
};
let wanted = DiscoveryOptions {
collapse_search_results: true,
..DiscoveryOptions::TODAY
};
let context = OpenHumanRunContext::new();
context.session_sidecar.lock().unwrap().discovery_record = Some(wanted);
let history = vec![
Message::system("prompt"),
Message::user("one"),
Message::assistant("first answer"),
Message::user("two"),
Message::assistant("second answer"),
];
let prior = OpenHumanTranscriptCodec
.reconcile(&[], &[], &history, &options(context))
.unwrap();
assert_eq!(DiscoveryOptions::recorded_in(&prior), Some(wanted));

// The compacted generation: a prompt with a freshly rendered memory block,
// a summary for the folded turn, and the verbatim tail.
let compacted = vec![
Message::system("prompt with a fresh memory block"),
Message::user("summary of the first turn"),
history[3].clone(),
history[4].clone(),
];
let rows = OpenHumanTranscriptCodec
.reconcile(
&prior,
&history,
&compacted,
&options(OpenHumanRunContext::new()),
)
.unwrap();
assert_eq!(DiscoveryOptions::recorded_in(&rows), Some(wanted));
assert!(
rows[1..].iter().all(|row| row.extra_metadata.is_none()),
"only the first row carries it"
);

// A thread that recorded nothing still records nothing.
let bare = OpenHumanTranscriptCodec
.reconcile(&[], &[], &history, &options(OpenHumanRunContext::new()))
.unwrap();
let rows = OpenHumanTranscriptCodec
.reconcile(
&bare,
&history,
&compacted,
&options(OpenHumanRunContext::new()),
)
.unwrap();
assert_eq!(DiscoveryOptions::recorded_in(&rows), None);
}

/// The history-replay pin rides the same compaction path as the discovery pin:
/// a thread created with expiry off but reasoning limited to the current turn
/// keeps both after a compacted generation drops the row that recorded them,
/// instead of falling back to whatever `[context]` says now.
#[test]
fn replay_pin_survives_compaction() {
use crate::agent::tinyagents::replay_pin::ReplayOptions;
use tinyagents_harness::reasoning_replay::ReasoningReplay;

let options = |context| TranscriptTurnOptions {
request_id: Some("turn".into()),
thread_id: None,
stream: false,
resume: ResumeMode::Never,
context,
};
let wanted = ReplayOptions {
replay_reasoning: ReasoningReplay::CurrentTurn,
..ReplayOptions::TODAY
};
let context = OpenHumanRunContext::new();
context.session_sidecar.lock().unwrap().replay_record = Some(wanted.clone());
let history = vec![
Message::system("prompt"),
Message::user("one"),
Message::assistant("first answer"),
Message::user("two"),
Message::assistant("second answer"),
];
let prior = OpenHumanTranscriptCodec
.reconcile(&[], &[], &history, &options(context))
.unwrap();
assert_eq!(ReplayOptions::recorded_in(&prior), Some(wanted.clone()));

// The compacted generation: a prompt with a freshly rendered memory block,
// a summary for the folded turn, and the verbatim tail.
let compacted = vec![
Message::system("prompt with a fresh memory block"),
Message::user("summary of the first turn"),
history[3].clone(),
history[4].clone(),
];
let rows = OpenHumanTranscriptCodec
.reconcile(
&prior,
&history,
&compacted,
&options(OpenHumanRunContext::new()),
)
.unwrap();
assert_eq!(ReplayOptions::recorded_in(&rows), Some(wanted));
assert!(
rows[1..].iter().all(|row| row.extra_metadata.is_none()),
"only the first row carries it"
);

// A thread that recorded nothing still records nothing.
let bare = OpenHumanTranscriptCodec
.reconcile(&[], &[], &history, &options(OpenHumanRunContext::new()))
.unwrap();
let rows = OpenHumanTranscriptCodec
.reconcile(
&bare,
&history,
&compacted,
&options(OpenHumanRunContext::new()),
)
.unwrap();
assert_eq!(ReplayOptions::recorded_in(&rows), None);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//! A thread's `tool_search` options are chosen when it is created, recorded on
//! its first transcript row, and read back on resume: a config that changes
//! later reaches new threads only.

use std::path::Path;

use tinyinference_llm::model::ModelResponse;

use super::transcript_compat_tests::{
build_host_with_config, model, run_async, store_tree, thread_id,
};
use crate::agent::tinyagents::discovery::DISCOVERY_METADATA_KEY;
use crate::config::schema::ToolSearchConfig;
use crate::config::AgentConfig;

fn agent_config(tool_search: ToolSearchConfig) -> AgentConfig {
AgentConfig {
tool_search,
..AgentConfig::default()
}
}

fn no_promotion() -> ToolSearchConfig {
ToolSearchConfig {
promote_found_tools: false,
collapse_search_results: true,
..ToolSearchConfig::default()
}
}

/// Runs one turn of `thread` on a fresh host over `root`, as a new process
/// would, and returns how many stored rows carry the recorded options.
async fn turn_and_count_records(root: &Path, thread: &str, tool_search: ToolSearchConfig) -> usize {
let next = model(vec![ModelResponse::assistant("ok")], true);
let mut host = build_host_with_config(root, next, true, thread, agent_config(tool_search));
host.turn("hello").await.expect("turn");
let session = host.session.clone().expect("bound session");
store_tree(root, thread, &session)
.values()
.map(|stored| stored.to_string().matches(DISCOVERY_METADATA_KEY).count())
.sum()
}

#[test]
fn a_new_thread_records_options_that_differ_from_today_once() {
run_async(async {
let root = tempfile::tempdir().expect("tempdir");
let thread = thread_id("pinned-new");
assert_eq!(
turn_and_count_records(root.path(), &thread, no_promotion()).await,
1,
"the turn that creates the thread records its options"
);
// A later process with a different config neither adds nor changes it.
assert_eq!(
turn_and_count_records(root.path(), &thread, ToolSearchConfig::default()).await,
1,
"a resumed thread keeps the record it started with"
);
});
}

#[test]
fn a_thread_created_with_todays_behaviour_records_nothing_and_stays_that_way() {
run_async(async {
let root = tempfile::tempdir().expect("tempdir");
let thread = thread_id("legacy-new");
assert_eq!(
turn_and_count_records(root.path(), &thread, ToolSearchConfig::default()).await,
0
);
// The config changes afterwards; the thread is not pinned to it.
assert_eq!(
turn_and_count_records(root.path(), &thread, no_promotion()).await,
0
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
&request.run_context.data.recorded_tool_names,
)?;
// Text dialects need the positional registry to recover P-Format and code-style calls.
let run_context = request.run_context.data.clone().with_tool_dialect(
let mut run_context = request.run_context.data.clone().with_tool_dialect(
tinyagents_harness::dialect::dispatcher_for_format(self.dispatcher.tool_call_format()),
);
// The turn builds its own `RunConfig`, so the options the session set on
// this request's config (result expiry, reasoning replay, discovery)
// have to be handed over here.
run_context.session_run_options =
crate::agent::tinyagents::host::run_context::SessionRunOptions::of(
&request.run_context.config,
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let cancellation = request.run_context.cancellation.clone();
// Boxing avoids worker-stack overflow in debug builds.
let turn = Box::pin(async move {
Expand Down
Loading
Loading