ASTRA API Reference Guide
This guide covers the ASTRA-facing modules in astra-apis for ASTRA 2.6.1. It lists actions, terms, formulae and events exposed by module annotations; Java helper classes and internal sensor callbacks are not callable APIs. The signatures and implementation notes were checked against the 2.6.1 source. Separate adapters are covered in Environments, LLM Integration and MAMS.
Using a module
Declare a module inside an agent:
agent Example {
module Console console;
module Strings strings;
plan +!main(list args) {
console.readString(string Name);
if (strings.startsWith(Name, "A")) {
console.println("Hello, " + Name);
}
}
}
Each declaration creates an instance associated with that agent. The identifier, such as console, is chosen by you. Classes in astra.lang can use short names; other classes require an import or a fully qualified declaration, such as module astra.util.DB db;.
Kind |
Use |
Example |
|---|---|---|
Action |
Statement; failure fails the calling intention |
|
Term |
Expression returning a typed value |
|
Formula |
Guard, condition, query or wait |
|
Event |
Trigger for a plan |
|
Action implementations return Java booleans for success or failure; you do not assign these booleans in ASTRA. An output parameter is shown as out T name: pass a typed unbound variable, for example console.readInt(int N);. Term results are shown in the result column. Formulae participate in reasoning, rather than being boolean term expressions. Java object types retain their class names and may require imports.
Indices are zero-based. Typed readers generally cast values instead of converting them, so the stored type must match. Actions that return failure can be handled using Failure Handling; methods that log errors or return null have their own limitations described below.
Module directory
Module |
Purpose |
|---|---|
Console input and output |
|
Beliefs, events, intention stacks and explanations |
|
Inspect function terms |
|
Predicate/function conversion and boolean formulae |
|
Numeric parsing, extrema and random integers |
|
Configure message transports |
|
Access Java objects through reflection |
|
Lists and Java collection conversion |
|
Legacy placeholder |
|
String tests, splitting and replacement |
|
Agent lifecycle and runtime management |
|
Dynamic subgoals and callable metadata |
|
What an agent remembers of a previous life (weak recovery) |
|
Periodic events |
|
Agent logging |
|
Runtime parsing and rule construction |
|
Inspect execution explanations |
|
JDBC database access |
|
Shared named key/value spaces |
|
Legacy logging wrapper |
Core modules
astra.lang.Console
Reads from Java standard input and writes to standard output. println includes the agent name and a newline; print omits both. Input readers bind their output parameter and require suitable input. readString also prints diagnostic messages in this implementation. There is no read(...) alias: use readString(...).
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print with agent prefix and newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print without prefix or newline. |
Action |
|
Print the canonical Java class name. |
Action |
|
Read and bind a int value. |
Action |
|
Read and bind a long value. |
Action |
|
Read and bind a float value. |
Action |
|
Read and bind a double value. |
Action |
|
Read and bind a string value. |
astra.lang.Debug
Prints internal state for diagnosis. Belief dumps show the ordinary belief base; use an environment adapter’s dump action for its observations. dumpAgentRulesForEvent filters using the event’s exact printed representation. These tools are intended for diagnostics, not as a stable data exchange format.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Print ordinary beliefs. |
Action |
|
Print beliefs matching a predicate name. |
Action |
|
Print the explanation stack. |
Action |
|
Print rules matching an event representation. |
Action |
|
Print the current intention stack. |
Action |
|
Print pending events. |
astra.lang.Functions
Inspects a funct, such as move("north", 3). functor returns its name and arity its argument count. Typed readers use zero-based argument indices. Numeric readers cast to the requested type; valueAsString uses the primitive value’s string representation. valueType returns the Java class name of a primitive argument and does not handle nested lists or functions.
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.Logic
toPredicate exposes a function term as a queryable predicate with the same name and arguments. toFunctor accepts a predicate formula; other formula kinds throw an exception. eval turns a boolean term value into a formula.
Kind |
Signature |
Result / behavior |
|---|---|---|
Formula |
|
Query a function term as a predicate. |
Formula |
|
Succeed exactly when the boolean is true. |
Term |
|
|
astra.lang.Math
Numeric parsers trim whitespace and use Java parsing rules; malformed or out-of-range input throws an exception. randomInt(bound) requires a positive bound and returns a value from zero inclusive to the bound exclusive. Unbounded randomInt() applies absolute value to a random Java integer: the minimum integer can remain negative. abs has the same minimum-integer overflow limitation. min, max and abs accept integers only.
Kind |
Signature |
Result / behavior |
|---|---|---|
Formula |
|
Succeed exactly when the boolean is true. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.Messaging
Configures transports used by ASTRA’s send statement. Install, configure and start each service once for the JVM. Transport classes must implement astra.messaging.MessageService and be on the classpath. installService logs construction errors but still returns success, so action success alone does not prove installation. Configuration keys depend on the transport. See Agent Communication.
module Messaging messaging;
plan +!main(list args) {
messaging.installService("local", "astra.messaging.LocalMQService");
messaging.startService("local");
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Install a named message transport. |
Action |
|
Configure a named transport. |
Action |
|
Start the named transport. |
astra.lang.ObjectAccess
Uses Java reflection on public fields. create requires a public no-argument constructor and returns an Object; a custom module is preferable when a strongly typed result is required. set returns failure for reflection errors, while getters throw. toList requires a Collection field. invoke looks up a method with no parameter types, so it is usable for public no-argument methods; it is not a general overloaded-method dispatcher. The string overload of is uses Java reference equality: use strings.equal(oa.getString(obj, "field"), "value") for content equality.
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Formula |
|
Compare a public field with a value; see string caveat. |
Formula |
|
Compare a public field with a value; see string caveat. |
Formula |
|
Compare a public field with a value; see string caveat. |
Formula |
|
Compare a public field with a value; see string caveat. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Write a public field. |
Action |
|
Write a public field. |
Action |
|
Write a public field. |
Action |
|
Write a public field. |
Term |
|
|
Action |
|
Invoke a public no-argument method. |
Formula |
|
Test Java class membership. |
Term |
|
|
astra.lang.Prelude
Provides list operations. add, addAt, remove, shuffle, sorting, swap and reverse mutate the supplied list; tail returns a new list. Do not use a head reader on an empty list. Sorting requires mutually comparable values. contains has no boolean or general object overload.
The *ValueFor readers find the first function term with the requested functor in a list, then read argument zero or the supplied index. A missing functor or mismatched type throws. fromASTRAList expects primitive-wrapped values; toASTRAList and toList wrap Java list entries. toObjectArray returns ASTRA term objects, rather than unwrapped Java values. mapToList creates [key, value] pairs; fromMap creates key(value) function terms. toMap accepts function terms or two-element lists and converts keys and values to strings.
module Prelude prelude;
plan +!main(list args) {
list Values = [3, 1, 2];
prelude.sort_asc(Values);
int First = prelude.headAsInt(Values);
int Count = prelude.size(Values);
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Append a value in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Insert at an index in place. |
Action |
|
Remove the indexed entry in place. |
Term |
|
|
Formula |
|
Test whether the collection is empty. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Formula |
|
Test membership or substring occurrence. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Randomly reorder in place. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Sort in ascending order in place. |
Action |
|
Sort in descending order in place. |
Action |
|
Exchange two indexed values in place. |
Action |
|
Reverse in place. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.Reflection
Legacy placeholder. addRole currently returns success without changing the agent; it does not implement dynamic role assignment. Use Multiple Inheritance for class reuse and Callable Goals for dynamic goal invocation.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
No-op placeholder; always succeeds. |
astra.lang.Strings
String comparisons are case-sensitive except equalsIgnoreCase. charAt uses a zero-based Java character index. split takes a Java regular expression, not a literal delimiter, and discards trailing empty tokens. replaceAll also uses Java regular expressions and replacement-group syntax.
module Strings strings;
plan +!main(list args) {
list Words = strings.split("one,two,three", ",");
string Clean = strings.replaceAll("room 12", "[0-9]+", "X");
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Formula |
|
Compare string contents. |
Formula |
|
Compare without case distinctions. |
Formula |
|
Test a prefix. |
Formula |
|
Test a suffix. |
Formula |
|
Test membership or substring occurrence. |
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.System
Manages agents registered through this module and the shared runtime. createAgent creates and schedules an agent; it does not post its main goal. Call setMainGoal separately. Names must be unique. terminateAgent permits the creator or the target itself to terminate the target; terminate affects the current agent. exit ends the JVM and all agents.
sleep delays the calling action in milliseconds. Prefer Timer for recurring work. Scheduler settings affect the shared runtime. env returns null for an unset variable. getType(name) returns "none" for an unknown agent. deconstruct captures serializable beliefs, name and type, not intentions, pending events or module state; reconstruct is not a complete runtime checkpoint.
hasChildren can encounter a null owner entry in this implementation; use getChildren() and a list-size check when needed. Rule/event manipulation uses Java runtime objects and is an advanced API.
module System system;
plan +!main(list args) {
system.createAgent("worker", "examples.Worker");
system.setMainGoal("worker", []);
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Succeed without an effect. |
Term |
|
|
Action |
|
Fail the calling action. |
Action |
|
Terminate the current agent. |
Action |
|
Create and schedule a named agent. |
Action |
|
Post main(args) to the named agent. |
Action |
|
Terminate an owned agent or self. |
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Enqueue a Java event. |
Action |
|
Add a runtime rule. |
Action |
|
Add or replace a runtime rule. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Formula |
|
Test whether an ASTRA class can be loaded. |
Formula |
|
Test for owned agents; see implementation caveat. |
Formula |
|
Test whether this agent has a creator. |
Action |
|
Stop the runtime and exit the JVM. |
Action |
|
Delay the action in milliseconds. |
Term |
|
|
Action |
|
Set scheduler thread pool size. |
Action |
|
Load a scheduler strategy class. |
Term |
|
|
Formula |
|
Test whether a name is registered. |
Term |
|
|
Action |
|
Create and schedule an agent from captured state. |
Term |
|
|
Action |
|
Set scheduler sleep duration in milliseconds. |
Action |
|
Print per-agent timing statistics. |
Action |
|
Enable or disable agent tracing. |
Action |
|
Set the current agent to stepping mode. |
astra.lang.Goals
Constructs native dynamic subgoals and reads named outputs. fromString returns a fresh astra.core.GoalInvocation, executed with ASTRA’s invoke statement. Each invocation executes once. Output readers require successful completion, the exact output name and the matching type. callables returns the agent’s callable contracts, including inherited metadata. See Callable Goals and Dynamic Invocation for a complete example and annotation rules.
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.Memory
Since ASTRA 2.6.0. Lets an agent that has been restarted recover from what it remembers of its previous life. This is weak recovery: as with weak migration, the agent’s data survives but its intentions do not. The agent starts afresh, with its initial beliefs, and decides itself what to take back. The memory never changes the agent’s beliefs.
The memory is kept by astra.trace.AgentMemory. Start the JVM with -Dastra.memory=<directory> to keep a memory for every agent. Each agent then has a snapshot, taken periodically and at shutdown, plus a log of changes. These record the agent’s beliefs and its goal set: the top-level achievement goals (!!goal, other than main) that it adopted and that had neither been achieved nor failed. Subgoals are not remembered, because they belong to an intention. When an agent with the same name is created again with the same directory, it receives a $memory.restarted() event. It keeps the memory until it calls memory.recovered(), so if it is restarted again mid-recovery, it gets the same memory again rather than the half-recovered state.
agent Main {
module Console console;
module Memory memory;
module Timer timer;
module System system;
types counter {
formula count(int);
formula counting(string);
}
rule +!main(list args) {
if (~memory.remembers()) {
console.println("starting afresh");
+count(0);
!!counting("tick");
}
}
rule $memory.restarted() {
if (memory.believed(count(int n))) {
console.println("remembered count " + n);
+count(n);
}
foreach (memory.wasPursuing(counting(string name))) {
console.println("resuming " + name);
!!counting(name);
}
memory.recovered();
}
rule +!counting(string name) {
timer.every(name, 500);
wait(false);
}
rule $timer.tick(string name) : count(int n) {
-+count(n + 1);
console.println("count " + (n + 1));
if (n + 1 == 6) system.exit();
}
}
Run it with MAVEN_OPTS="-Dastra.memory=memory" mvn compile astra:deploy and stop it after count 3. Run it again with the same directory. It prints remembered count 3 and resuming tick, then continues from count 4. believed and wasPursuing are formulae with one solution for each remembered belief or goal that matches the pattern, so foreach visits every match.
Kind |
Signature |
Result / behavior |
|---|---|---|
Event |
|
The agent has a memory of a previous life. |
Formula |
|
True if the agent remembers a previous life and has not yet called |
Formula |
|
One solution for each remembered belief that matches the pattern, binding its variables. |
Formula |
|
One solution for each remembered goal that matches the pattern, binding its variables. |
Term |
|
|
Action |
|
The agent has recovered; its memory of the previous life is forgotten. |
astra.lang.Timer
Schedules periodic events without a sleeping intention. Intervals are positive milliseconds. The first tick occurs after one interval. Reusing a timer name replaces that agent’s existing timer; cancel also succeeds if no timer exists. Timers stop when their agent terminates. Tick handling follows normal event scheduling, so keep handlers short enough for the chosen interval.
module Timer timer;
module Console console;
plan +!main(list args) {
timer.every("refresh", 1000);
}
plan $timer.tick("refresh") {
console.println("refresh");
timer.cancel("refresh");
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Schedule or replace a named periodic timer. |
Action |
|
Cancel this agent’s named timer. |
Event |
|
Named periodic tick. |
astra.lang.Logger
Wraps Java logging using the agent’s name. Use supported uppercase level strings. Java handler configuration also controls which messages appear. setLogProperties loads a Java logging configuration file. The current INFO() term incorrectly returns "FINEST"; use the literal "INFO" or the info action. The other level terms return their named levels.
module Logger logger;
plan +!main(list args) {
logger.setLevel("INFO");
logger.info("agent ready");
}
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Set the logger threshold. |
Action |
|
Load Java logging configuration. |
Action |
|
Log a message at the given level. |
Action |
|
Log at FINER level. |
Action |
|
Log at FINE level. |
Action |
|
Log at CONFIG level. |
Action |
|
Log at INFO level. |
Action |
|
Log at WARNING level. |
Action |
|
Log at SEVERE level. |
astra.lang.Compiler
Experimental runtime parsing of rules, events and formulae. Returned objects can be passed to the corresponding System actions. Parse errors may be logged with a null result; the output-parameter compileRule action can return success without binding its output after a parse error. Validate input and results before installing runtime rules. This is not the Maven build compiler.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Parse a runtime rule. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
astra.lang.ExplanationAccess
Advanced access to the agent’s explanation store. Uses astra.core.Rule and astra.explanation.Explanation Java objects. Retrieval can be filtered by rule or tag; tag/value methods narrow the match. Check isEmpty and hasRule before reading explanation contents. See Debug for a console dump.
Kind |
Signature |
Result / behavior |
|---|---|---|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Formula |
|
Test for an associated rule. |
Formula |
|
Test whether the collection is empty. |
Term |
|
|
astra.util.DB
JDBC database access. Declare module astra.util.DB db; and add your database’s JDBC driver dependency. getConnection binds a java.sql.Connection; close it when finished. Query builders return astra.util.SQLQuery objects. Supply parallel field/value lists of matching lengths. Raw SQL methods execute the supplied SQL directly; construct and validate SQL for your database deliberately. where adds constraints to a query, get executes a selection and binds a list of rows, and update executes a modification.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Load a JDBC driver class. |
Formula |
|
Test for a database table. |
Action |
|
Open a JDBC connection. |
Action |
|
Close a JDBC connection. |
Action |
|
Execute raw modification SQL. |
Action |
|
Execute raw selection SQL and bind rows. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Action |
|
Add query constraints. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Action |
|
Execute a selection query and bind rows. |
Term |
|
|
Action |
|
Execute a modification query. |
astra.util.TupleSpace
Shared in-process named key/value spaces. Declare module astra.util.TupleSpace tuples;. Join a space before posting or reading; use hasSpace and hasTuple before typed getters. A post associates a key with a value and can replace that value. These getters read without consuming the entry. Values must match the requested getter type. Space membership is per agent; the data is shared among participants in the JVM.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Join a named space. |
Action |
|
Leave a named space. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Action |
|
Store or replace a keyed value. |
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Term |
|
|
Formula |
|
Test whether a keyed value exists. |
Formula |
|
Test whether a named space exists. |
Term |
|
|
astra.util.Logging
Legacy Java logging wrapper. Declare module astra.util.Logging logging;. Its accepted level names and logger configuration follow Java logging. Prefer astra.lang.Logger for new agents; the legacy wrapper also exposes a finest action.
Kind |
Signature |
Result / behavior |
|---|---|---|
Action |
|
Set the logger threshold. |
Action |
|
Log a message at the given level. |
Action |
|
Log at SEVERE level. |
Action |
|
Log at WARNING level. |
Action |
|
Log at INFO level. |
Action |
|
Log at FINE level. |
Action |
|
Log at FINER level. |
Action |
|
Log at FINEST level. |