AI Conversations
Your app’s AI agents are not only reachable from the chat. The app’s own code can hold conversations with them too, and every conversation of the app is recorded in the app’s data backend, where the code reads it like any other table. With the IronFlock SDK, an app can:
- start a conversation with one of its agents on behalf of a project member, send it prompts and stop a running turn;
- follow its conversations in the tables
ai-conversationsandai-messages, whether a person started them in a board’s AI chat or the code did; - tell which conversation called a tool: a function the app registered as an agent’s tool learns the conversation and the agent that called it, and can store that with what it creates.
A conversation belongs to the app that started it, in the stage (development or production) that started it. The app only ever sees its own conversations.
The Conversation Tables
The platform records the app’s conversations in two tables of the app’s own data backend. They exist in every app; you do not declare them in data-template.yml.
| Table | One row per | Columns |
|---|---|---|
ai-conversations | Version of a conversation: every change adds a row. The entity is conversation_id | tsp, conversation_id, state (THINKING, WAITING or IDLE), title, agent, agent_app_key, user_account_key, user_name, origin (widget or sdk), widget_key, scope (json), started_by_device_key, deleted |
ai-messages | Finished message or tool call | tsp, conversation_id, message_id, role (user, assistant, tool, question or confirmation), text, agent, tool_name, tool_args (json), tool_status, device_key |
state tells where a conversation stands: THINKING while an agent works on a turn, WAITING when the agent asked the person something and waits for the answer, IDLE when the turn is over. origin tells who started it: widget for a person in a board’s AI chat, sdk for the app’s code.
- Only the platform writes them. Appends from the app or a board are refused. Both tables are empty until the app has its first conversation.
- What they hold: the users’ prompts, each conversation’s state, the agents’ questions and confirmations, the app’s own tool calls and the answers of the app’s own agents. Never the IronFlock assistant’s answers, and nothing of other apps.
- Streamed text is not stored. A message appears once it is finished; while an agent works, only
stateinai-conversationschanges. - Tool calls are recorded under the conversation’s
conversation_id, also those of the sub-agents it delegated to, with the agent’s name inagent. - Deleting keeps the messages. A conversation the user deletes gets a new version with
deleted = true; its rows inai-messagesstay. - They are private to the app. Only the app’s code, its transforms and its own board’s bindings can read them. Other apps never see them, also not through cross-app data access.
A board widget bound to these tables shows every user’s conversations to everyone who can open the board. Bind them on a board only when that is intended.
Reading the Tables
Subscribe to ai-messages to act on every finished message as it arrives, and query either table like any other. ai-conversations holds a version per change, so read it with the latest marker to get the current state of each conversation.
Python
# Every finished message and tool call, as it happens
async def on_message(row, **kwargs):
if row["role"] == "assistant":
print(row["conversation_id"], row["text"])
await ironflock.subscribe_to_table("ai-messages", on_message)
# The messages of one conversation, oldest first
messages = await ironflock.getHistory("ai-messages", {
"limit": 500,
"filterAnd": [{"column": "conversation_id", "operator": "=", "value": conversation_id}],
})
# The current state of every conversation
conversations = await ironflock.getHistory("ai-conversations", {
"limit": 100,
"filterAnd": [{"latest": True}],
})Starting a Conversation from Code
createConversation / create_conversation / CreateConversation starts a conversation with one of the app’s own agents, as ai-template.yml names it. The IronFlock assistant cannot be chosen. The platform takes the project, the app and the stage from the app’s connection, so the conversation belongs to the app that started it, and only that app, in the same stage, can send prompts to it or stop it. It appears in ai-conversations with origin sdk.
A conversation always runs on behalf of a person: user is the account key of a member of the project, the number that user_account_key holds in ai-conversations. The agent’s tools then act with that person’s rights. The platform refuses any account that is not a member of the project.
sendPrompt / send_prompt / SendPrompt sends a prompt and, by default, waits until the agent’s turn ends:
Python
conversation_id = await ironflock.create_conversation(
user=1234, # a project member's account key
agent="case", # an agent from the app's ai-template.yml
scope={"case_id": "C-1042"},
)
reply = await ironflock.send_prompt(conversation_id, "Summarize case C-1042.")
print(reply.get("response")) # None when the prompt was only queuedscope describes what the conversation is about. It is stored with the conversation in the scope column, so the app can find its conversations about a case, a machine or an order again. context passes further information to the agent; context.language (for example "de") sets the language of the conversation, English by default.
What a Prompt Returns
| When | Answer |
|---|---|
| The app waits (the default) and the turn runs | When the agent’s turn ends: success, response (the agent’s answer), conversation_id, tools_used, usage and error. A turn that failed or was stopped has success false and an error |
| The app waits, but a turn already runs in the conversation | At once: the prompt is queued for the running turn, with queued true and no response. With outcome "returned", the turn ended without taking the prompt: send it again |
| The app does not wait | At once: success and queued true, and the conversation_id. Follow the conversation in the tables |
Only an answer that waited for the turn carries a response; read it in a way that allows it to be missing. The SDK sets no time limit on the wait. When your code stops waiting, the agent’s turn goes on; stop it with cancelConversation / cancel_conversation / CancelConversation. The conversation keeps its messages and takes further prompts.
Questions and Confirmations
An agent can end a turn with a question. The conversation is then WAITING, and the next prompt is the answer.
Nobody sees a confirmation form in a conversation the app started. So a tool that asks a person to confirm before it runs, a tool marked as able to delete or overwrite (see Tool Titles and Annotations), is refused there, and the agent is told that it cannot run it. Give the agents you call from code tools they may run without a confirmation.
Limits
Per app and stage, the platform allows:
| What | Limit |
|---|---|
| Conversations started | 10 a minute |
| Prompts sent | 30 a minute |
| Conversations with a running turn | 5 at once |
Beyond them, a call is refused with ironflock.ai.rate_limited. A refused prompt does not count.
Errors
A call the platform refuses fails with one of these WAMP error URIs. Read the URI from the error as for every other refusal: in Python with wamp_error_uri(err), in JavaScript from the WampError’s error, in Go with ironflock.WampURI(err), in C# from the OperationFailedException’s WampErrorUri.
| URI | Meaning |
|---|---|
ironflock.ai.not_a_member | user, or the person a conversation runs for, is not a member of the project |
ironflock.ai.agent_not_found | The app has no agent of that name |
ironflock.ai.conversation_not_found | No conversation of this app and stage has that ID. Conversations that people started in a board’s chat count as not found: an app sends prompts only to the conversations it started itself |
ironflock.ai.rate_limited | Beyond one of the limits above |
ironflock.ai.unavailable | The platform’s AI service could not store or read the conversation just then |
The calls ride out a short loss of the connection like the table operations (see Connection Reliability). When no AI service answers on the app’s connection at all, the error says that the platform’s AI service is not available.
Which Conversation Called a Tool
When an agent calls a tool that the app registered with registerDeviceFunction / register_device_function / RegisterDeviceFunction (see Registering AI Agent Functions), the platform tells the function which conversation the call belongs to. Inside the function, the call context holds:
conversation_id: the conversation a person or the app started, also when an agent it delegated to made the call. It matchesconversation_idinai-conversationsandai-messages.agent: the name of the calling agent asai-template.ymldeclares it, orrouterfor the IronFlock assistant.
The call context is empty when the function was not called by an AI agent: by a board’s action, by another device or by a direct call. The function’s own arguments do not change.
Store the conversation with what the tool creates, and the app can later show which conversation led to a record, or read the conversation that explains it:
Python
from ironflock import call_context
async def create_case(title: str, description: str = ""):
ctx = call_context() # None unless an AI agent called
await ironflock.append_to_table("cases", {
"tsp": datetime.now(timezone.utc).isoformat(),
"title": title,
"description": description,
"conversation_id": ctx["conversation_id"] if ctx else None,
})
return {"created": title}
await ironflock.register_device_function("cases.create", create_case)The call context is set for the duration of the call, also across the awaits of an asynchronous function. How far it reaches into work the function starts differs by language; the SDK reference says what holds in each.
SDK Versions
The functions on this page are available from ironflock-py 1.12.0, ironflock-js 1.12.0, sdk-go 1.12.0 and the IronFlock NuGet package 1.12.0.