Embed
Invoke or extend another Circuit via the `circuit.core.embed` primitive
Introduction to Embed
The circuit.core.embed primitive lets you call an existing Circuit (yours or a community-shared one) as a sub-workflow within your own Circuit. It:
- Posts your inputs and target CircuitVersion to the ModelWorks runtime
- Waits for that embedded Circuit to finish
- Pulls back all of its outputs (and performance reports) into your parent Circuit’s execution context
Use embed to compose higher-level logic, share reusable building blocks, and foster ecosystem growth.
Step Syntax
{
"name": "<step_name>",
"description": "Optional description",
"function": "circuit.core.embed",
"conditions": [
{ "expression": "${{ <selector> }}" }
],
"query": {
"context": {
"version": "<TARGET_VERSION_UID>"
},
"input": {
/* key/value pairs matching the embedded Circuit’s inputs */
"foo": "${{ input.foo }}",
"bar": 123
}
}
}-
name A unique identifier for this step.
-
description (optional) Document purpose or behavior.
-
function Must be
"circuit.core.embed". -
conditions (optional) Array of pre-conditions (selectors) that must all resolve to
truebefore running. -
query.context.version The UUID of the CircuitVersion to invoke.
-
query.input An object whose keys exactly match the target Circuit’s input names. Values can be literals or selectors like
"${{ ... }}".
Outputs & Performance
When the embedded Circuit completes:
- All of its outputs appear under
<step_name>.output.outputs.<outputName> - Performance reports (time taken, CPU/RAM usage) appear under
<step_name>.output.performance_reports
Reference them via JSON-style selectors:
"${{ openai_query_extend.output.outputs.chat_completion_output }}"Cost Implications
Embedding a Circuit adds that Circuit’s credit cost to your parent Circuit’s total. This:
- Keeps billing transparent
- Rewards authors for shared Circuits
- Enables rapid composition without duplicating logic
Example
Embed a shared “OpenAI-4.0” chat Circuit:
{
"name": "openai_query_extend",
"description": "Invoke community Chat-4.0 Circuit",
"function": "circuit.core.embed",
"conditions": [
{ "expression": "${{ input.messages.length > `0` }}" }
],
"query": {
"context": {
"version": "01e03926-ad5f-4992-9b18-56bbfb192c72"
},
"input": {
"messages": "${{ input.messages }}"
}
}
}Then consume its output:
{
"name": "final_output",
"value": "${{ openai_query_extend.output.outputs.chat_completion_output }}"
}By embedding optimized, battle-tested Circuits you accelerate your own workflows and help grow the ModelWorks community!