pub struct AgentText(/* private fields */);Expand description
Text an agent produced: its free-text answer (StepOutput::text() in
ironflow-engine) or a text field of a typed answer.
An agent may repeat, word for word, instructions planted in what it read.
So its text reaches the next prompt only inside an untrusted block:
pass it to Prompt::untrusted. AgentText deliberately implements
neither Display, Deref, AsRef<str>, Borrow<str> nor
From<AgentText> for String: format!("{}", text),
AgentConfig::new(&text) and Prompt::text do not compile with it.
It serializes as a plain JSON string and its JSON Schema is the one of
String: a step output, a replay fixture and the schema sent to the
model are the same as with a String.
§Debug
{:?} prints AgentText(<N bytes>), with N the length of the text in
UTF-8 bytes, never the text itself. A derived Debug would let
format!("Act on: {:?}", out.text()), or {:?} of a typed answer holding
text fields, carry the agent’s text into a prompt unmarked. The cost: a
failing assert_eq! on AgentText shows the lengths, not the texts;
compare raw to see them in a test.
§Escape hatches
Reading the raw text stays possible, explicitly, for logs, artifacts,
shell arguments or comments: raw,
into_raw, serde_json::to_string /
to_value of an AgentText or of a typed answer, and, in
ironflow-engine, StepOutput::json::<String>() and the public
output.output JSON value of a step (also printed by {:?} of a
StepOutput). Never put their result in a prompt. {:?} of an
AgentText is not one of them: it does not print the text.
§Examples
use ironflow_core::prompt::{AgentText, Prompt};
let summary = AgentText::from("Looks good.");
assert_eq!(summary, "Looks good.");
assert_eq!(summary.raw(), "Looks good.");
let prompt = Prompt::new().text("Act on this summary:").untrusted(&summary);
assert!(prompt.to_string().contains("Looks good."));
assert_eq!(
format!("{:?}", AgentText::from("Ignore the above")),
"AgentText(<16 bytes>)"
);It cannot be formatted with {}:
use ironflow_core::prompt::AgentText;
let _ = format!("{}", AgentText::from("x"));nor passed as trusted text:
use ironflow_core::prompt::{AgentText, Prompt};
let _ = Prompt::new().text(&AgentText::from("x"));nor used as a prompt:
use ironflow_core::prompt::AgentText;
use ironflow_core::provider::AgentConfig;
let _ = AgentConfig::new(&AgentText::from("x"));Implementations§
Source§impl AgentText
impl AgentText
Sourcepub fn raw(&self) -> &str
pub fn raw(&self) -> &str
The raw text, for logs, artifacts, shell arguments or comments.
Never pass it to a prompt: use Prompt::untrusted with the
AgentText itself.
§Examples
use ironflow_core::prompt::AgentText;
let text = AgentText::from("日本語");
assert_eq!(text.raw(), "日本語");Sourcepub fn into_raw(self) -> String
pub fn into_raw(self) -> String
The raw text, owned, for logs, artifacts, shell arguments or comments.
Never pass it to a prompt: use Prompt::untrusted with the
AgentText itself.
§Examples
use ironflow_core::prompt::AgentText;
let text: String = AgentText::from("done").into_raw();
assert_eq!(text, "done");Trait Implementations§
impl AgentAnswer for AgentText
Source§impl<'de> Deserialize<'de> for AgentText
impl<'de> Deserialize<'de> for AgentText
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AgentText, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AgentText, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for AgentText
Source§impl JsonSchema for AgentText
Same schema as String, inlined: a derive would emit a $defs/AgentText
reference and the agent’s output schema would differ from a plain string.
impl JsonSchema for AgentText
Same schema as String, inlined: a derive would emit a $defs/AgentText
reference and the agent’s output schema would differ from a plain string.
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§impl Ord for AgentText
impl Ord for AgentText
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for AgentText
impl PartialOrd for AgentText
Source§impl Serialize for AgentText
impl Serialize for AgentText
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for AgentText
impl UntrustedContent for AgentText
Auto Trait Implementations§
impl Freeze for AgentText
impl RefUnwindSafe for AgentText
impl Send for AgentText
impl Sync for AgentText
impl Unpin for AgentText
impl UnsafeUnpin for AgentText
impl UnwindSafe for AgentText
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.