SDK reference

Everything your program can say to Inflowave. The same calls exist in Python and in Node.

Beta: request access. Code agents are in beta and are switched on for each agency by hand. Names and limits can still change. Request access

Install

pip install inflowave-agent
npm install @inflowave/agent

Both packages have no other packages to install. Python needs 3.9 or newer, Node needs 18 or newer. If you use the command line tool, pip install inflowave-cli installs the Python SDK too. When Inflowave builds your agent from a folder with main.py or main.js, it installs the SDK for you. If you bring your own Dockerfile, install the SDK there.

Python uses snake_case names and Node uses camelCase.

Python

from inflowave_agent import Agent

with Agent() as agent:            # or: async with Agent() as agent:
    data = agent.get_input()
    agent.push_data({"title": data["keyword"]})
    agent.charge("result")

All methods are quick calls and are safe inside async code. Only ask waits. In async code use await agent.ask_async(...).

MethodWhat it does
get_input()The buyer's input as a dict. An empty dict when there is none.
push_data(item_or_list)Adds result rows. Rows are objects; anything else is stored as {"value": ...}. Returns how many were added.
set_value(key, obj)Saves one named JSON value, such as a summary or a cursor. A key is 1 to 80 characters: letters, digits, and the characters - _ .
get_value(key, default=None)Reads a value saved earlier in this run. On your computer it also reads values from earlier local runs.
save_file(path_or_bytes, name=None, mime=None)Saves a file to the run's output. Bytes need a name. The name is flattened to a plain file name.
log(msg, level), debug, info, warn, errorLog lines that you and the buyer can read.
progress(pct, msg="")Progress from 0 to 100, with an optional note.
ask(question, options=None, kind="text", id=None, timeout=None)Asks the buyer and waits for the answer. See below. Raises AskTimeout or AskError.
charge(event, count=1)Charges a result event listed in your manifest. Count is 1 to 10,000. Returns False when the buyer's spending limit is reached.
limit_reachedTrue once the spending limit for the run is reached.
done(summary=None)Marks the run as a success. Called for you at the end of the with block.
fail(reason)Marks the run as failed. The program exits with code 1 at the end of the block.

If your code raises an error, the SDK logs the details, reports a failure and exits with code 1. You do not need your own error handling for that.

Options when you create the agent object: storage_dir, poll_interval (seconds, default 1), ask_timeout (seconds, default 3600), exit_on_error (default true) and quiet.

Node

import { Agent } from '@inflowave/agent';

await Agent.main(async (agent) => {
  const data = await agent.getInput();
  await agent.pushData({ title: data.keyword });
  agent.charge('result');
});
MethodNotes
getInput()The buyer's input.
pushData(item)Adds result rows.
setValue(key, value), getValue(key)Save and read one named value.
saveFile(pathOrBytes, name, mime)Saves a file to the run's output.
log, debug, info, warn, errorLog lines.
progress(pct, msg)Progress from 0 to 100.
ask(question, { options, kind, id, timeout })Asks the buyer and waits.
charge(event, count)Returns false when the spending limit is reached.
limitReachedTrue once the spending limit is reached.
done(summary), fail(reason)Mark success or failure.

Agent.main reports success when your function returns, and reports a failure with the error details (exit code 1) when it throws. Type definitions are included.

Asking the buyer

The run pauses and the buyer sees your question in the app. Your program waits for the answer.

audience = agent.ask(
    "Who is this for?",
    options=["Beginners", "Experts"],
    kind="choice",
    id="audience",
)
const audience = await agent.ask('Who is this for?', {
  options: ['Beginners', 'Experts'],
  kind: 'choice',
  id: 'audience',
});
KindThe answer is
textA line of text. This is the default.
long_textLonger text.
choiceOne of your options. At most 20 options.
approve"approve" or "reject".
numberA number.

If nobody answers in time, ask raises AskTimeout. Give every question a stable id (letters, digits, - and _, up to 64 characters) while you build. A question is at most 300 characters.

On your computer, in a terminal, you answer at the prompt. Without a terminal, put the answer in storage/answers/<id>.json, for example storage/answers/audience.json:

{ "answer": "Experts" }

Charging

Your program calls charge when it has produced something the buyer should pay for. The name must be one of the result events you list under pricing.events in the manifest. A charge for an event that is not listed is refused.

The buyer sets the most one run may cost. When that limit is reached, charge returns False, nothing is charged, and your program should stop early. A run that fails charges nothing. Free test runs are never charged.

for keyword in keywords:
    brief = write_brief(keyword)
    agent.push_data(brief)
    if not agent.charge("result"):
        break                      # the buyer's spending limit for this run is reached

Local mode

When the program is not running inside Inflowave, the SDK is in local mode. The calls are the same, and everything goes to files on your computer.

CallWhat happens locally
InputRead from storage/input.json, or from the file you give to inflowave agents run.
push_dataAppended to storage/dataset.jsonl.
set_valueWritten to storage/kv/<key>.json.
save_fileWritten to storage/out/.
Every callAlso appended to storage/events.jsonl.
askA prompt in the terminal, or a file in storage/answers/.
chargePrinted and added up, never billed.

inflowave agents run clears the output of the last run first. Add the keep option to keep it.

Limits

WhatLimit
Run timeThe timeout_s in your manifest, at most 3,600 seconds
MemoryThe memory_mb in your manifest, 512 to 8,192
Waiting for an answer3,600 seconds by default
Result rows100,000 per run, each up to 256 KB. All are kept in dataset.jsonl; the first 500 show on the run page.
Saved values200 per run
Output files200 files, 100 MB each, 500 MB in total. Extra files are skipped, with a warning in the log.
One event line512 KB. A log message is cut at 4,000 characters.
Log kept for youThe last 500 lines
A question300 characters, up to 20 options

Do not print secrets in your logs. Under the hood, the SDK talks to Inflowave through a simple protocol called inflowave.run/v1, which is fixed. You only need it if you want to write an agent in another language.

Want to build one?

Tell us about your agency and what you would like to build. We will switch the beta on for your account.