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
8 changes: 5 additions & 3 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ _Avoid_: System prompt — that is the Character Prompt, which carries this and

**Character Prompt**:
The opening turn of the Director session: Personality Prompt, Instance Prompt,
the Behaviors it may propose, and this moment. Later wakes send a short
follow-up (what just happened, recent Behaviors, time of day, State, what the
the Behaviors it may propose, the Instance's own id for its tool calls, and this
moment. Later wakes send a short
follow-up (the Instance's id, what just happened, recent Behaviors, time of day, State, what the
user is doing) in the same conversation. Assembled rather than written: two of its
layers are authored, the whole is never hand-authored. The Prompt tab shows
the three concatenated layers — app-level instructions, Personality Prompt,
Expand All @@ -58,7 +59,8 @@ The Director mode that empties the built-in prompt layers — the package
Personality Prompt and the app-level instructions (voice rules, Behavior roster,
reply contract) — and still sends an Instance Prompt the user wrote. Off by
default. The Prompt tab shows those emptied fields as Empty: what you see is
what is sent. With no contract the reply is prose, so the character talks and plays
what is sent, apart from the Instance id line, which stays so tool calls still
reach this Instance. With no contract the reply is prose, so the character talks and plays
no Behavior unless the Instance Prompt asks for one. That is the control run
for telling a model's misbehaviour apart from the shipped prompt, and for
iterating a prompt under Fidget's conditions. #657, #680.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,11 @@ Fidget attaches to a Harness over ACP on stdio. The Harness calls back over MCP,
| `describe_screen` | Sensing | Describe screen (v1: window metadata only) |
| `recall` | Memory | Read everything Memory holds |
| `remember` | Memory | Write one fact under a heading |
| `list_instances` | Identity | List Character Instances and their names |
| `list_instances` | Identity | List Character Instances: id, name, and the three Character Prompt layers |
| `whereabouts` | Placement | Which display each Instance is on, the other displays, and its feet in that display. Each display includes its name when the platform has one, its origin, and its size, in logical points |

Every tool takes an optional `instance_id`. Each Character Instance has its own Harness session, and that session's opening turn names its id, so `speak` and `play_behavior` land on the Instance whose session called them. An id no running Instance has is refused.

**Three readonly resources** (`resources/list`, `resources/read`; no write, no subscribe):

| URI | What it is |
Expand Down
79 changes: 58 additions & 21 deletions crates/core/src/director.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ use crate::sensing::Activity;

mod prompt;
mod recency;
#[cfg(test)]
use prompt::follow_up;
pub use prompt::{app_instructions, happened_word, typed_line};
pub(crate) use prompt::{character_prompt, follow_up};
pub(crate) use prompt::{character_prompt, named_moment};
pub use recency::{Doing, Lately, Recency, Step};

/// How long the Static Director goes unwoken when nothing notable happens.
Expand Down Expand Up @@ -351,9 +353,9 @@ impl<C: Completer> ModelDirector<C> {
/// The user turn for this wake. Settings shows this string.
pub fn prompt(&self, context: &Context) -> String {
if self.opened.load(Ordering::SeqCst) {
follow_up(context)
named_moment(context, &self.instance)
} else {
character_prompt(context, self.behaviors.iter(), self.blank)
character_prompt(context, &self.instance, self.behaviors.iter(), self.blank)
}
}

Expand Down Expand Up @@ -1844,7 +1846,7 @@ mod tests {
fn the_completer_is_sent_the_character_prompt() {
let director = directing(Scripted::says("wave"), ["wave"]);
let moment = context(working(), &["nap"]);
let expected = character_prompt(&moment, ["wave"], false);
let expected = character_prompt(&moment, "buddy-1", ["wave"], false);

director.wake(&moment);

Expand Down Expand Up @@ -2145,7 +2147,7 @@ mod tests {
caffeinate: None,
};

let payload = character_prompt(&moment, ["greet", "stroll", "wave"], false);
let payload = character_prompt(&moment, "buddy-1", ["greet", "stroll", "wave"], false);

assert!(
payload.contains("Blip is cheerful."),
Expand Down Expand Up @@ -2208,7 +2210,7 @@ mod tests {
fn an_empty_instance_prompt_assembles_the_payload_it_always_did() {
let moment = context(working(), &["nap"]);

let payload = character_prompt(&moment, ["wave"], false);
let payload = character_prompt(&moment, "buddy-1", ["wave"], false);

assert!(
payload.starts_with("a shy robot.\n\nYou may propose one of these behaviors: wave"),
Expand All @@ -2226,7 +2228,7 @@ mod tests {
..context(working(), &["nap"])
};

let payload = character_prompt(&moment, ["wave"], false);
let payload = character_prompt(&moment, "buddy-1", ["wave"], false);

let personality = payload.find("a shy robot.").expect("the author's layer");
let instance = payload.find("Answer in haiku.").expect("the user's layer");
Expand All @@ -2250,12 +2252,15 @@ mod tests {
..context(working(), &["nap"])
};

let shaped = character_prompt(&moment, ["wave"], false);
let blank = character_prompt(&moment, ["wave"], true);
let shaped = character_prompt(&moment, "buddy-1", ["wave"], false);
let blank = character_prompt(&moment, "buddy-1", ["wave"], true);

assert!(
blank.starts_with("Answer in haiku.\n\nwhat just happened:"),
"the Instance Prompt is still in front of the moment: {blank}"
blank.starts_with(
"Answer in haiku.\n\nYour instance_id is buddy-1. \
Pass it to every Fidget tool you call.\n\nwhat just happened:"
),
"the Instance Prompt and the id are still in front of the moment: {blank}"
);
assert!(
!blank.contains("a shy robot."),
Expand Down Expand Up @@ -2298,7 +2303,7 @@ mod tests {
#[test]
fn a_request_invites_the_tools_without_naming_them() {
let moment = context(working(), &["nap"]);
let opening = character_prompt(&moment, ["wave"], false);
let opening = character_prompt(&moment, "buddy-1", ["wave"], false);

assert!(
opening.contains(
Expand Down Expand Up @@ -2348,18 +2353,50 @@ mod tests {
}

#[test]
fn blank_mode_without_an_instance_prompt_is_the_moment() {
fn blank_mode_without_an_instance_prompt_is_the_id_and_the_moment() {
let moment = context(working(), &["nap"]);
let blank = character_prompt(&moment, ["wave"], true);
assert_eq!(blank, follow_up(&moment));
let blank = character_prompt(&moment, "buddy-1", ["wave"], true);
assert_eq!(
blank,
format!(
"Your instance_id is buddy-1. Pass it to every Fidget tool you call.\n\n{}",
follow_up(&moment)
)
);
}

/// Each session's opening names its own Instance, so a tool call made
/// from it lands there and not on another Instance.
#[test]
fn every_turn_names_this_instance() {
let moment = context(working(), &["nap"]);
let pip = character_prompt(&moment, "pip", ["wave"], false);
let rex = character_prompt(&moment, "rex", ["wave"], false);

assert!(pip.contains("Your instance_id is pip."), "{pip}");
assert!(rex.contains("Your instance_id is rex."), "{rex}");
assert!(!pip.contains("rex"), "{pip}");

// A session the Harness opened mid-run hears only follow-ups, so they
// carry the id too.
let director = directing(Scripted::says("wave"), ["wave"]);
director.wake(&moment);
let later = director.prompt(&moment);
assert!(
later.starts_with(
"Your instance_id is buddy-1. Pass it to every Fidget tool you call.\n\n"
),
"{later}"
);
assert!(!later.contains("always in character"), "{later}");
}

/// Each rule the opening turn must carry, and that later wakes do not
/// repeat them.
#[test]
fn the_character_prompt_carries_the_voice_rules_once() {
let moment = context(working(), &["nap"]);
let payload = character_prompt(&moment, ["wave"], false);
let payload = character_prompt(&moment, "buddy-1", ["wave"], false);

assert!(
payload.contains("always in character"),
Expand Down Expand Up @@ -2405,7 +2442,7 @@ mod tests {
.completer
.seen_prompt()
.expect("a follow-up was sent");
assert_eq!(sent, follow_up(&later));
assert_eq!(sent, named_moment(&later, "buddy-1"));
assert!(
!sent.contains("a shy robot."),
"personality is the opening only: {sent}"
Expand Down Expand Up @@ -2517,7 +2554,7 @@ mod tests {
Some(line),
"follow-up: {line:?}"
);
let opening = character_prompt(&moment, ["wave"], false);
let opening = character_prompt(&moment, "buddy-1", ["wave"], false);
assert_eq!(typed_line(&opening), Some(line), "opening: {line:?}");
}
}
Expand All @@ -2531,7 +2568,7 @@ mod tests {
};
assert_eq!(typed_line(&follow_up(&ambient)), None);
assert_eq!(
typed_line(&character_prompt(&ambient, ["wave"], false)),
typed_line(&character_prompt(&ambient, "buddy-1", ["wave"], false)),
None
);
assert_eq!(typed_line("an ordinary prompt"), None);
Expand All @@ -2546,7 +2583,7 @@ mod tests {
..typed("hello?")
};
assert_eq!(
typed_line(&character_prompt(&moment, ["wave"], false)),
typed_line(&character_prompt(&moment, "buddy-1", ["wave"], false)),
Some("hello?")
);
}
Expand Down Expand Up @@ -2909,7 +2946,7 @@ mod tests {
.completer
.seen_prompt()
.expect("a follow-up was sent");
assert_eq!(sent, follow_up(&asked));
assert_eq!(sent, named_moment(&asked, "buddy-1"));
assert!(
!sent.contains("a shy robot."),
"personality is the opening only: {sent}"
Expand Down
21 changes: 17 additions & 4 deletions crates/core/src/director/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use super::{Context, Doing, Happened, Lately, State, Step, CHAT_LIMIT};

/// The opening turn: Personality Prompt, Instance Prompt (ADR-0012), roster
/// and moment; later wakes send `follow_up`. `blank` empties the built-in
/// layers for the control run, keeping the rest; its reply is prose.
/// The opening turn: Personality Prompt, Instance Prompt (ADR-0012), roster,
/// the Instance's own id and moment; later wakes send `named_moment`. `blank`
/// empties the built-in layers for the control run, keeping the rest; its
/// reply is prose.
pub(crate) fn character_prompt(
context: &Context,
instance: &str,
behaviors: impl IntoIterator<Item = impl AsRef<str>>,
blank: bool,
) -> String {
let moment = follow_up(context);
let moment = named_moment(context, instance);

// Empty, not `(no personality)`: that placeholder is a Character with an
// empty file, which still gets the voice rules. Blank AI is the emptied
Expand Down Expand Up @@ -40,6 +42,17 @@ pub(crate) fn character_prompt(
}
}

/// The moment, led by this Instance's id. Every turn carries the id, and
/// blank mode keeps it: it routes tool calls to this Instance, which is
/// plumbing rather than voice, and a session the Harness opened mid-run hears
/// only follow-ups.
pub(crate) fn named_moment(context: &Context, instance: &str) -> String {
format!(
"Your instance_id is {instance}. Pass it to every Fidget tool you call.\n\n{}",
follow_up(context)
)
}

/// The app layer of the Character Prompt: voice rules, roster, reply contract.
/// Empty under Blank AI, which the Prompt tab shows frozen. Paid every wake,
/// so the tools describe themselves over MCP; a copy here would drift.
Expand Down
Loading
Loading