operation
Write a custom Ironflow Operation - an integration (GitLab, Slack, any HTTP API) executed as a tracked step through ctx.operation(). Loaded by the ironflow hub for the operation verb.
- License 许可
- MIT
- 最近更新
- 2026-11-04
- Stars
- ★ 2
- Forks
- 1
01 前言 Front Matter
- name
- operation
- description
- Write a custom Ironflow Operation - an integration (GitLab, Slack, any HTTP API) executed as a tracked step through ctx.operation(). Loaded by the ironflow hub for the operation verb.
- user-invocable
- false
02 资源文件 2
- 参考文档references/gitlab-issue.md3.9 KB
- 参考文档references/http-json.md3.0 KB
03 SKILL.md 正文
Ironflow operation
Operation is the extension point for step kinds Ironflow does not ship. The engine owns the lifecycle (step record, status, duration, output persistence); the operation owns the call.
Built-in kinds already exist for a plain shell command, an HTTP request and an agent. Write an operation when the step needs its own struct, its own error mapping, or its own structured output. A single ctx.http() is enough for a one-off request.
1. Gather the shape
One AskUserQuestion call: operation name (snake_case struct, lowercase kind()), the external call it makes, its inputs, what the step output must contain, and where the credential comes from (a secret, an env var on the worker).
2. Write the operation
One file per operation in the workflows crate under src/operations/. Template:
use async_trait::async_trait;
use ironflow_core::operations::http::Http;
use ironflow_core::error::OperationError;
use ironflow_core::operation::{Operation, OperationContext};
use serde_json::{Value, json};
/// Posts a message to a Slack channel through an incoming webhook.
pub struct SlackMessage {
pub webhook_url: String,
pub text: String,
}
#[async_trait]
impl Operation for SlackMessage {
fn kind(&self) -> &str {
"slack"
}
fn input(&self) -> Option<Value> {
// Persisted as the step input. Never include the credential.
Some(json!({"text": self.text}))
}
async fn execute(&self, _ctx: &OperationContext) -> Result<Value, OperationError> {
let resp = Http::post(&self.webhook_url)
.json(json!({"text": self.text}))
.await?;
if !resp.is_success() {
return Err(OperationError::Http {
status: Some(resp.status()),
message: format!("slack answered {}", resp.status()),
});
}
Ok(json!({"status": resp.status()}))
}
}
Two complete examples to copy from: references/http-json.md (generic JSON API wrapper with typed response) and references/gitlab-issue.md (create a GitLab issue via ironflow-ops-gitlab, typed queries and tracked operations).
3. Call it from a handler
use async_trait::async_trait;
use ironflow_core::error::OperationError;
use ironflow_core::operation::{Operation, OperationContext};
use ironflow_engine::context::WorkflowContext;
use ironflow_engine::error::EngineError;
use serde::Deserialize;
use serde_json::{Value, json};
/// What `Ping` returns, read back typed from the step output.
#[derive(Deserialize)]
struct Pong {
ok: bool,
}
struct Ping;
#[async_trait]
impl Operation for Ping {
fn kind(&self) -> &str {
"ping"
}
async fn execute(&self, _ctx: &OperationContext) -> Result<Value, OperationError> {
Ok(json!({"ok": true}))
}
}
async fn example(ctx: &mut WorkflowContext) -> Result<(), EngineError> {
let pong: Pong = ctx.operation("ping-upstream", &Ping).await?.json()?;
let _ok = pong.ok;
Ok(())
}
The step is stored with kind custom:<kind()>, so keep kind() short, lowercase and stable.
An Err from execute fails the step and the run. When the workflow should carry on, call ctx.operation_allow_failure(name, &op) instead: the step is still recorded as Failed, the run ends as Warning, and the handler reads the message through error() on the returned output.
4. Verify
cargo build -p workflows
cargo test -p workflows
Add a test of the operation alone when it is pure enough (build the struct, call execute().await, assert on the JSON). For HTTP calls, test through a workflow with a real local server or leave it to the end-to-end test of the calling handler.
Rules
- Errors are
OperationError. Wrap transport errors asOperationError::Http { .. }, secret errors asOperationError::Secret { .. }.Httperrors fromironflow_core::operations::http::Httpconvert with?already. input()is observability, not secrets. It lands in the database and the dashboard.- Output is JSON. Return what later steps need (ids, urls, status), not the raw response body when it is large.
- No retry loops inside
execute(). Retries are a step concern: the run fails, the operator retries the run. OperationContextprovidesctx.http_client()(sharedreqwest::Client) andctx.secrets()(aSecretResolver). Usectx.secrets().get("key").await?to fetch credentials insideexecute(), or read them in the handler and pass them into the struct.- External crates depend on
ironflow-coreonly, notironflow-engine. TheOperationtrait andOperationContextlive inironflow-core::operation.
04 同仓库更多 Skills
workflow
Write an Ironflow WorkflowHandler - typed input schema, steps (shell, http, agent, approval, human input, signal, decision, sub-workflow, parallel), registration in handlers(). Loaded by the ironflow hub for the workflow verb.
upgrade
Upgrade the Ironflow crates of a project and migrate its code, or audit existing code against the current Ironflow idioms. Reads the changelog between the installed and the target release, maps every change to the project's code, then proposes or applies the migrations. Loaded by the ironflow hub for the upgrade and audit verbs.
test
Write an end-to-end test for an Ironflow workflow handler - real Engine, InMemoryStore, RecordReplayProvider fixtures, assertions on run status and step names. Loaded by the ironflow hub for the test verb.
setup
Scaffold a new Ironflow project - a Cargo workspace with a workflows lib, an API server binary, a worker binary, a hello workflow and its end-to-end test. Loaded by the ironflow hub for the setup verb.
ironflow
Entry point for building on the Ironflow workflow engine. Use for setting up an Ironflow project (server + worker), writing a WorkflowHandler, writing a custom Operation, testing a workflow end to end, reviewing a handler, upgrading the ironflow crates and migrating the code, or auditing existing code against the current Ironflow idioms. Trigger on "ironflow", "workflow handler", "ironflow setup", "ctx.shell", "ctx.agent", "approval gate", "upgrade ironflow", "bump ironflow", "créer un workflow ironflow", "mettre en place ironflow", "mettre à jour ironflow", "migrer ironflow".
ops-crate
Generate a new ops/xxx crate for an external service integration. Identifies the right pattern (A=wrapper, B=HTTP direct, C=macro), scaffolds the full structure, and runs the quality checklist. Trigger on "ops crate", "new ops", "creer un crate ops", "add ops/xxx", "nouveau crate ops", "ironflow ops".