Documentation
¶
Overview ¶
Package remote runs an agent launched by the controller (cmd/controller) with the settings and the records of the controller, which alone reaches the database, through its internal API (see agentapi): the flags of its settings, its secrets, the switches of its control panel and the prompt of an LLM agent as they change while it runs, and the storage of its orders, of its decisions and of its journal.
Nothing of the flow of the agent waits for the controller: its records are written to an outbox of its own, a file sent to the controller as it answers, and read back from memory. The controller refusing its token, eg: the agent left running by a controller before, the agent stops.
Index ¶
- Variables
- type Agent
- func (a *Agent) Args() []string
- func (a *Agent) ClaimEntry(pair string, side model.SideType) (bool, string)
- func (a *Agent) Close() error
- func (a *Agent) Decisions(ctx context.Context) (*Decisions, error)
- func (a *Agent) Gate(gate *agentapi.PairGate)
- func (a *Agent) Journal() *Journal
- func (a *Agent) KeepBotStopped(ctx context.Context, bot BotSwitch)
- func (a *Agent) Open(dir string) error
- func (a *Agent) Orders(ctx context.Context) (*Orders, error)
- func (a *Agent) Prompt() llm.Prompt
- func (a *Agent) Prompts() *Prompts
- func (a *Agent) Protect(protection Protection)
- func (a *Agent) Run(ctx context.Context, apply func(agentapi.Runtime)) context.Context
- func (a *Agent) Serve(ctx context.Context, apply func(agentapi.Runtime), ...) error
- func (a *Agent) Supervise(controller Entries)
- type BotSwitch
- type Client
- func (c *Client) Attachment(ctx context.Context, id string, index int) (string, []byte, error)
- func (c *Client) CheckOutbox(ctx context.Context, records []agentapi.Record) error
- func (c *Client) ClaimEntry(ctx context.Context, pair, side string) (agentapi.ExposureAnswer, error)
- func (c *Client) Config(ctx context.Context) (agentapi.Config, error)
- func (c *Client) Decision(ctx context.Context, id string) (ui.Decision, bool, error)
- func (c *Client) DecisionLinks(ctx context.Context) (map[int64]string, error)
- func (c *Client) Decisions(ctx context.Context, pair string, limit int) ([]ui.Decision, error)
- func (c *Client) DecisionsPerPair(ctx context.Context, perPair int) ([]ui.Decision, error)
- func (c *Client) Discards(ctx context.Context) ([]model.Discard, error)
- func (c *Client) JournalMemory(ctx context.Context, perPair int) ([]agentapi.Remembered, error)
- func (c *Client) LeaseOrderIDs(ctx context.Context, count int64) (agentapi.OrderIDs, error)
- func (c *Client) Orders(ctx context.Context, after int64, limit int) ([]model.Order, error)
- func (c *Client) Outbox(ctx context.Context, request agentapi.OutboxRequest) (uint64, error)
- func (c *Client) Prompt(ctx context.Context) (agentapi.Prompt, bool, error)
- func (c *Client) Runtime(ctx context.Context, version int64, wait time.Duration) (agentapi.Runtime, bool, error)
- type Decisions
- func (s *Decisions) Attachment(id string, index int) (string, []byte, error)
- func (s *Decisions) Decision(id string) (ui.Decision, bool, error)
- func (s *Decisions) Decisions(pair string, limit int) ([]ui.Decision, error)
- func (s *Decisions) OrderDecision(orderID int64) string
- func (s *Decisions) Save(d ui.Decision, attachments []llm.Attachment) error
- type Entries
- type Journal
- type Notifier
- type Orders
- func (o *Orders) Close() error
- func (o *Orders) CreateDiscard(discard model.Discard) error
- func (o *Orders) CreateOrder(order *model.Order) error
- func (o *Orders) Discards() ([]model.Discard, error)
- func (o *Orders) Orders(filters ...storage.OrderFilter) ([]*model.Order, error)
- func (o *Orders) SetNotifier(notifier Notifier)
- func (o *Orders) UpdateOrder(order *model.Order) error
- type Outbox
- type Prompts
- type Protection
- type RefusedError
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ErrOutboxCorrupt = errors.New("remote: the outbox can't be read")
ErrOutboxCorrupt is the error of an outbox whose file can't be read, see OpenOutbox.
ErrUnauthorized is the answer of the controller to a token it didn't give, or gave to a start of the agent that ended: the agent isn't the one it runs, eg: left running by a controller before, and must stop.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
Config agentapi.Config
APIKey string
QuarantineOutbox bool
// contains filtered or unexported fields
}
Agent is an agent launched by the controller: its settings, the key of its API for this start (see ui.WithAPIKey), and what it keeps through the controller once Open. With QuarantineOutbox, eg: the flag -outbox-quarantine, Open moves an outbox that can't be read aside rather than failing, see OpenOutbox.
func Connect ¶
Connect returns the agent launched by the controller, its settings read from it, nil when the agent runs on its own: without the token of the controller in its environment (agentapi.EnvToken).
func (*Agent) ClaimEntry ¶
ClaimEntry claims an entry of the bot on pair on side of the controller, while the exposure limit of the agents is on (see agentapi.Entries), before the bot sends it: whether it may go, and why not. A claim that can't be asked refuses the entry, the limit unknown.
func (*Agent) Close ¶
Close stops sending the records and watching the runtime, writes the orders the outbox failed to write a last time, sends the records left, flushTimeout at most, and closes the outbox. After Serve, the bot stopped.
func (*Agent) Decisions ¶
Decisions returns the store of the decisions of the LLM agent, see NewDecisions.
func (*Agent) Gate ¶
Gate has the assets the strategy of the bot may open positions on follow the ones the controller tells (see agentapi.Entries.EntriesPairs): the ones of its settings at once, then the ones of its runtime as they change, with its entries. Before Run.
func (*Agent) KeepBotStopped ¶
KeepBotStopped stops the bot of the agent once it starts, when a user left it stopped (see agentapi.Config.BotStopped): its process started again by a deploy, a reboot, a crash or Reiniciar never trades until a user starts it (Iniciar bot, /start), the bot starting with the agent (see xtrader.Run). Called before the bot runs, it returns at once; nothing without Config.BotStopped.
func (*Agent) Open ¶
Open opens the outbox of the agent in dir, eg: data/outbox, a file named after it and its ID, eg: llm-3.db: a new agent taking the name of one deleted never sends the records the other left. Before its records are kept. A file that can't be read fails with ErrOutboxCorrupt, unless QuarantineOutbox: then it is moved aside, to <file>.corrupt-<time>, and the agent starts with an empty outbox (the records of a file read but those it can't, set apart).
func (*Agent) Orders ¶
Orders returns the storage of the orders of the agent, see NewOrders, the orders it failed to write written again by Close.
func (*Agent) Prompt ¶
Prompt returns the prompt selected for the LLM agent, its default one when none is.
func (*Agent) Prompts ¶
Prompts returns the source of the prompts of the LLM agent, nil for an agent of another kind.
func (*Agent) Protect ¶
func (a *Agent) Protect(protection Protection)
Protect has the protection of the positions of the bot follow the one the controller tells (see agentapi.Protection): the one of its settings at once, before the bot trades, then the one of its runtime as it changes, with its entries, before its prompt. Before Run.
func (*Agent) Run ¶
Run sends the records of the outbox to the controller, and applies the runtime of the agent as it changes: its prompt, kept by Prompts, and its switches, handed to apply with the rest, once at first. It returns the context of the agent: done with ctx, or when the controller refuses the agent, which must then stop, ErrUnauthorized its cause. After Open.
func (*Agent) Serve ¶
func (a *Agent) Serve(ctx context.Context, apply func(agentapi.Runtime), run func(context.Context) error) error
Serve runs the agent (see Run) and its bot with run, until the bot ends or the context of the agent is done: a signal, or the controller refusing the agent, ErrUnauthorized then. Then the bot stops trading before Serve returns: run must return once its context is done, the orders it executed recorded in the outbox, as xtrader.XTrader.Run does, so that Close sends and closes an outbox nothing writes an order to any more.
func (*Agent) Supervise ¶
Supervise has the entries of the bot of controller follow the ones the controller tells (see agentapi.Entries): the ones of its settings at once, before the bot trades, then the ones of its runtime as they change, before its prompt, whose switch may fail: a block never waits for it. Before Run.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the internal API of the controller for an agent, with the token of its start (see agentapi).
func NewClient ¶
NewClient returns the client of the internal API at baseURL, eg: http://127.0.0.1:8090, authenticated with token.
func (*Client) Attachment ¶
Attachment returns the attachment index of the decision id and its media type, ui.ErrUnknownDecision when there is none.
func (*Client) CheckOutbox ¶
CheckOutbox asks the controller whether it writes the records, none written: nil when it does, a *RefusedError naming the one it refuses for good.
func (*Client) ClaimEntry ¶
func (c *Client) ClaimEntry(ctx context.Context, pair, side string) (agentapi.ExposureAnswer, error)
ClaimEntry claims an entry on pair on side against the exposure limit of the agents, see agentapi.ExposureClaim.
func (*Client) DecisionLinks ¶
DecisionLinks returns the decision that placed each order of the agent.
func (*Client) Decisions ¶
Decisions returns the last decisions of pair, of every pair when empty, newest first, limit at most.
func (*Client) DecisionsPerPair ¶
DecisionsPerPair returns the last decisions of each pair, perPair of them.
func (*Client) Discards ¶
Discards returns the positions the order controller of the agent discarded, by the fill after which each one was.
func (*Client) JournalMemory ¶
JournalMemory returns the last decisions of each pair of the journal of the agent, perPair of them.
func (*Client) LeaseOrderIDs ¶
LeaseOrderIDs leases count order IDs.
func (*Client) Orders ¶
Orders returns the orders of the agent after the ID after, by ID, limit at most.
func (*Client) Outbox ¶
Outbox writes the records of request, and returns the Seq of the last one written: a *RefusedError names the record refused, none written.
type Decisions ¶
type Decisions struct {
// contains filtered or unexported fields
}
Decisions is the store of the decisions of an LLM agent launched by the controller (llm.DecisionStore): each saved through the outbox, the last ones held in memory with the decisions that placed the orders, which the chart reads holding its lock, the older ones read from the controller.
func NewDecisions ¶
NewDecisions returns the decisions of the agent: the last ones of the controller, and the ones of the outbox not sent yet, newer.
func (*Decisions) Attachment ¶
Attachment implements llm.DecisionStore.
func (*Decisions) Decisions ¶
Decisions implements llm.DecisionStore: the ones held, with the older ones of the controller when they are too few, or else alone while the controller is out of reach.
func (*Decisions) OrderDecision ¶
OrderDecision implements llm.DecisionStore, from memory.
type Entries ¶
type Entries interface {
BlockEntries(revision int64, reason string) bool
AllowEntries(revision int64) bool
}
Entries is the order controller of a bot whose entries the controller blocks and allows again, eg: *order.Controller, see Supervise.
type Journal ¶
type Journal struct {
// contains filtered or unexported fields
}
Journal is the journal of an LLM agent launched by the controller (llm.Journal): each call to the model written through the outbox, the memory of its prompt read back from the controller.
func NewJournal ¶
NewJournal returns the journal of the agent.
type Notifier ¶
Notifier is told of the orders the outbox fails to write and of their write at last, eg: the chart of the bot, which the controller relays to Telegram.
type Orders ¶
type Orders struct {
// contains filtered or unexported fields
}
Orders is the storage of the orders of an agent launched by the controller (storage.Storage): in memory, each change written through the outbox, the orders numbered with IDs leased from the controller ahead of their need, so CreateOrder never waits for it: the order is at the broker already when it is called. The orders are handed as copies. A state of an order older than the one kept is neither kept nor written, as the controller would refuse it (see model.Order.Supersedes), eg: the copy of a move written after a fill.
The order at the broker already, a failure of the outbox, eg: a full disk, is never an error of CreateOrder nor of UpdateOrder: the order kept in memory is followed by the bot all the same, the failure logged and notified, and its last state written again until the outbox takes it, see Close.
func NewOrders ¶
NewOrders returns the orders of the agent: the ones of the controller, and the ones of the outbox not sent yet, newer, with the IDs leased to it; so are the positions its order controller discarded. The next IDs are leased until ctx is done or Close, see lease.
func (*Orders) Close ¶
Close stops leasing the next order IDs and writing the orders unwritten again, after a last attempt, as the agent stops, before its outbox is flushed: it returns the error of the ones still unwritten, never sent to the controller.
func (*Orders) CreateDiscard ¶
CreateDiscard keeps a position the order controller discarded, written through the outbox, once: the controller keeps it once too. A failure of the outbox is its error, the discard kept in memory for this run only.
func (*Orders) CreateOrder ¶
CreateOrder numbers the order and keeps it. It never fails: the order is at the broker already, see Orders.
func (*Orders) Orders ¶
Orders returns copies of the orders the filters keep, by their update, as the storage of the files did.
func (*Orders) SetNotifier ¶
SetNotifier sets who is told of the orders the outbox fails to write.
type Outbox ¶
type Outbox struct {
// contains filtered or unexported fields
}
Outbox is the queue of the records an agent keeps through the controller: each written to a file of its own before Add returns, in order, then sent to the controller in batches as it answers (see Run), so the agent neither waits for the controller nor loses a record while it is out of reach. A record the controller refuses for good is set apart, and one it fails again and again alone while it writes the next ones of its kind, held apart (see send): the next ones sent.
The file is a buntdb synced by the outbox itself after each write, whose failure is an error of the write, and never rewritten by buntdb, whose rewrite syncs neither the new file nor its directory: the outbox compacts it itself, durably (see compact). A record written is lost only with the disk or a machine that lies about its syncs.
func OpenOutbox ¶
OpenOutbox opens the outbox of file, eg: data/outbox/llm-3.db, its records sent with client, locked for this process: another process of the agent, eg: left running by a controller before, holds it. A file that can't be read, eg: written over in the middle, fails with ErrOutboxCorrupt, left as it is, see openOutboxFile; one cut short, eg: the agent killed in the middle of a write, opens with the records before the cut.
func (*Outbox) Add ¶
Add writes the record of kind and key, of the JSON of payload, at the end of the outbox, on disk when it returns, and wakes the sender. A record the file fails to sync is an error, sent all the same while the agent runs.
func (*Outbox) Flush ¶
Flush sends the records left until none is, the controller refusing the agent, or ctx done, eg: as the agent stops: then it fails, telling how many are left, sent by the next start.
type Prompts ¶
type Prompts struct {
// contains filtered or unexported fields
}
Prompts is the source of the prompts of an LLM agent launched by the controller (llm.PromptSource): the prompt selected for it, kept as the runtime of the agent changes (see Agent.Run), so the Trader reads it without a request. What comes of each prompt is told to the controller through the outbox (llm.PromptReporter).
func (*Prompts) ReportPrompt ¶
func (p *Prompts) ReportPrompt(ref ui.DecisionPrompt, err error)
ReportPrompt implements llm.PromptReporter.
type Protection ¶
type Protection interface {
Apply(settings *ui.ProtectionSettings, arms []ui.ProtectionArm)
ApplyDailyStops(stops []ui.DailyStop)
}
Protection is the protection of the positions of the bot as the controller sets it, see agentapi.Protection and protect.Manager.
type RefusedError ¶
RefusedError is the answer of the controller to a batch of the outbox whose record at Index it refuses for good, none of them written.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
type StatusError ¶
StatusError is an answer of the controller other than a success.
func (*StatusError) Error ¶
func (e *StatusError) Error() string