Package edu.uky.cs.nil.tt
package edu.uky.cs.nil.tt
This library provides the abstract classes
Client
and ClientFactory for implementing
Tandem Tales agents in Java.
Client handles connecting to the server and joining a session. A
minimal subclass of Client only needs to implement the onChoice(Status) method to
choose what the agent will do on its turn.
ClientFactory continuously creates new clients to connect to the
server and wait for partners. A minimal subclass of ClientFactory only needs
to implement the create() method to return a
new Client instance.
Here is an example client and factory:
package edu.uky.cs.nil.tt;
import java.util.List;
import java.util.Random;
import edu.uky.cs.nil.tt.world.Status;
import edu.uky.cs.nil.tt.world.Turn;
public class RandomAgent extends Client {
private final Random random = new Random();
public RandomAgent() {
super("random", null, null);
}
@Override
protected int onChoice(Status status) throws Exception {
List<Turn> choices = status.getChoices();
int choice = random.nextInt(choices.size());
System.out.println(choices.get(choice).getDescription());
return choice;
}
}
package edu.uky.cs.nil.tt;
public class RandomAgentFactory extends ClientFactory {
@Override
protected Client create() throws Exception {
return new RandomAgent();
}
public static void main(String[] args) throws Exception {
try(RandomAgentFactory factory = new RandomAgentFactory()) {
factory.call();
}
}
}
Both classes have other lifecycle methods that are meant to be overridden.
Client has the following lifecycle methods:
onConnect(Connect), which runs after it connects to the server.onStart(World, Role, State), which runs after its session starts.onUpdate(Status), which runs each time the server sends a state update (even if it is not the client's turn).onChoice(Status), which runs each time the server sends a state update and it is the client's turn.onEnd(Ending), which runs if the story session reaches a pre-defined ending.onClose(), which runs after the client ends its session without throwing an exception.onStop(String), which runs after the client's session has ended.onDisconnect(), which runs after the client has disconnected.
ClientFactory has the following lifecycle methods:
onStart(), which runs after the factory starts.onClose(), which runs after the factory begins shutting down.onStop(), which runs before the factory stops.
Client also provides a way to call an external
API for expensive operations like text embedding and text completion.
embed(String)lets you convert a text string to an array of floats.complete(String...)lets you generate text that is a fitting continuation of a sequence of messages.
-
ClassDescriptionA client connects to a
serverto find a partner and play arolein a storytellingsession.A client factory continuously createsclientsto connect to aserverand is useful for deploying automated agents.The external API is how aclientcontacts remote services to perform computations the client cannot perform on its own.Represents the different levels of effort that can be used by a reasoning model duringtext completion.