Class AgentActivity<P>
- Type Parameters:
P- how the caller identifies a peer, the other agent of a message
The record is held in memory by the agent that owns it, and ActivityBlock renders it
for that agent's LLM. It is not a log: nothing is written out.
Two caps bound it: a number of entries, and a number of characters over all entries, counting each entry's text and type. When an entry would take the record over either, the oldest entries are dropped until it fits. The newest entry is always kept, because a third cap, on the characters of one entry's type and text together, cuts a longer one short before it is kept and may not exceed the whole. The type is cut first, then the text to what the type leaves.
Every text and type passes through the redactor before the record cuts it, so the record's
own cut cannot leave behind the start of something the redactor would have hidden. A text the
caller already cut short before recording it is redacted as it arrives. Line breaks in a text
or type are replaced by a space after redaction, so an entry stays one line when it is rendered.
Peers are kept as the caller identifies them; ActivityBlock names them through the
caller's function, which is responsible for what a name shows.
- Since:
- 0.18.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne entry of the record.static enumWhat an entry of the record describes. -
Constructor Summary
ConstructorsConstructorDescriptionAgentActivity(int maxEntries, int maxChars, int maxEntryChars, UnaryOperator<String> redactor) Creates an empty record. -
Method Summary
Modifier and TypeMethodDescriptionvoidRecords an action the agent's LLM called.voidRecords a note the agent wrote.read()Returns a stable snapshot of the record, oldest first.voidRecords a message the agent received.voidRecords a message the agent sent.
-
Constructor Details
-
AgentActivity
public AgentActivity(int maxEntries, int maxChars, int maxEntryChars, UnaryOperator<String> redactor) Creates an empty record.- Parameters:
maxEntries- the most entries the record holdsmaxChars- the most characters of text and type the record holds over all its entriesmaxEntryChars- the most characters one entry's type and text hold togetherredactor- applied to every text and type before it is kept, outside the record's lock and so possibly from several threads at once; it must be thread-safe, and an exception it throws reaches the caller and nothing is recorded. Anullit returns is kept as the empty text, or as no type- Throws:
IllegalArgumentException- if a cap is less than one, ormaxEntryCharsexceedsmaxCharsNullPointerException- ifredactorisnull- Since:
- 0.18.5
-
-
Method Details
-
sent
public void sent(double tick, List<? extends P> receivers, String type, String text, boolean textTruncated) Records a message the agent sent.- Parameters:
tick- the tick at which it was sentreceivers- the agents it was sent to;nullis nonetype- the message type, ornullwhen it has nonetext- the message texttextTruncated- whether the caller already cuttextshort- Throws:
NullPointerException- ifreceiversholds anull- Since:
- 0.18.5
-
received
Records a message the agent received.- Parameters:
tick- the tick at which it was receivedsender- the agent that sent it, ornullwhen it is not knowntype- the message type, ornullwhen it has nonetext- the message texttextTruncated- whether the caller already cuttextshort- Since:
- 0.18.5
-
acted
Records an action the agent's LLM called.- Parameters:
tick- the tick at which it ranaction- the action's namefailed- whether it failedoutcome- what it returned, or why it failed- Since:
- 0.18.5
-
noted
Records a note the agent wrote.- Parameters:
tick- the tick at which it was writtennote- the note- Since:
- 0.18.5
-
read
Returns a stable snapshot of the record, oldest first.- Returns:
- an immutable list that later recording does not change
- Since:
- 0.18.5
-