TT Client Library 1.0.0
C++ library for Tandem Tales clients.
Loading...
Searching...
No Matches
Tandem Tales Client (C++)

This library provides the abstract classes tt::Client and tt::ClientFactory for implementing Tandem Tales agents in C++.

tt::Client handles connecting to the server and joining a session. A minimal subclass of tt::Client only needs to implement the tt::Client::onChoice method to choose what the agent will do on its turn.

tt::ClientFactory continuously creates new clients to connect to the server and wait for partners. A minimal subclass of tt::ClientFactory only needs to implement the tt::ClientFactory::create method to return a new Client instance.

Here is an example client and factory:

#include <tt/Client.h>
#include <tt/ClientFactory.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
class RandomAgent : public tt::Client {
public:
RandomAgent(const std::string &url, int port):
tt::Client("random", "", tt::Role::NONE, "", url, port) {}
int onChoice(const tt::Status* status) override {
const auto& choices = status->getChoices();
int count = choices.size();
std::srand(std::time(nullptr));
int choice = std::rand() % count;
std::cout << choices[choice]->getDescription() << std::endl;
return choice;
}
};
class RandomAgentFactory : public tt::ClientFactory {
public:
std::unique_ptr<tt::Client> create() const override {
return std::make_unique<RandomAgent>("localhost", 9005);
}
};
int main() {
RandomAgentFactory factory;
factory.execute();
}

Both classes have other lifecycle methods that are meant to be overridden.

tt::Client has the following lifecycle methods:

tt::ClientFactory has the following lifecycle methods:

tt::Client also provides a way to call an external API for expensive operations like text embedding and text completion. It does so through its tt::Client::external member variable.

This more complete example shows you everything you need to download and run a Tandem Tales server and connect a custom C++ agent.