@modelrelay/sdk 5.1.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,80 +98,35 @@ const text = await mr.responses.textForCustomer({
98
98
 
99
99
  ## Workflows
100
100
 
101
- High-level helpers for common workflow patterns:
101
+ Build multi-step AI pipelines with the workflow helpers.
102
102
 
103
- ### Chain (Sequential)
104
-
105
- Sequential LLM calls where each step's output feeds the next step's input:
103
+ ### Sequential Chain
106
104
 
107
105
  ```ts
108
- import { chain, llmStep } from "@modelrelay/sdk";
106
+ import { chain, llm } from "@modelrelay/sdk";
109
107
 
110
- const summarizeReq = mr.responses
111
- .new()
112
- .model("claude-sonnet-4-5")
113
- .system("Summarize the input concisely.")
114
- .user("The quick brown fox...")
115
- .build();
116
-
117
- const translateReq = mr.responses
118
- .new()
119
- .model("claude-sonnet-4-5")
120
- .system("Translate the input to French.")
121
- .user("") // Bound from previous step
108
+ const spec = chain([
109
+ llm("summarize", (n) => n.system("Summarize.").user("{{task}}")),
110
+ llm("translate", (n) => n.system("Translate to French.").user("{{summarize}}")),
111
+ ], { name: "summarize-translate", model: "claude-sonnet-4-5" })
112
+ .output("result", "translate")
122
113
  .build();
123
114
 
124
- const spec = chain("summarize-translate")
125
- .step(llmStep("summarize", summarizeReq))
126
- .step(llmStep("translate", translateReq).withStream())
127
- .outputLast("result")
128
- .build();
115
+ const { run_id } = await mr.runs.create(spec);
129
116
  ```
130
117
 
131
- ### Parallel (Fan-out with Aggregation)
132
-
133
- Concurrent LLM calls with optional aggregation:
118
+ ### Parallel with Aggregation
134
119
 
135
120
  ```ts
136
- import { parallel, llmStep } from "@modelrelay/sdk";
137
-
138
- const gpt4Req = mr.responses.new().model("gpt-4.1").user("Analyze this...").build();
139
- const claudeReq = mr.responses.new().model("claude-sonnet-4-5").user("Analyze this...").build();
140
- const synthesizeReq = mr.responses
141
- .new()
142
- .model("claude-sonnet-4-5")
143
- .system("Synthesize the analyses into a unified view.")
144
- .user("") // Bound from join output
145
- .build();
146
-
147
- const spec = parallel("multi-model-compare")
148
- .step(llmStep("gpt4", gpt4Req))
149
- .step(llmStep("claude", claudeReq))
150
- .aggregate("synthesize", synthesizeReq)
151
- .output("result", "synthesize")
152
- .build();
153
- ```
154
-
155
- ### MapReduce (Parallel Map with Reduce)
156
-
157
- Process items in parallel, then combine results:
158
-
159
- ```ts
160
- import { mapReduce } from "@modelrelay/sdk";
161
-
162
- const combineReq = mr.responses
163
- .new()
164
- .model("claude-sonnet-4-5")
165
- .system("Combine summaries into a cohesive overview.")
166
- .user("") // Bound from join output
167
- .build();
168
-
169
- const spec = mapReduce("summarize-docs")
170
- .item("doc1", doc1Req)
171
- .item("doc2", doc2Req)
172
- .item("doc3", doc3Req)
173
- .reduce("combine", combineReq)
174
- .output("result", "combine")
121
+ import { parallel, llm } from "@modelrelay/sdk";
122
+
123
+ const spec = parallel([
124
+ llm("agent_a", (n) => n.user("Write 3 ideas for {{task}}.")),
125
+ llm("agent_b", (n) => n.user("Write 3 objections for {{task}}.")),
126
+ ], { name: "multi-agent", model: "claude-sonnet-4-5" })
127
+ .llm("aggregate", (n) => n.system("Synthesize.").user("{{join}}"))
128
+ .edge("join", "aggregate")
129
+ .output("result", "aggregate")
175
130
  .build();
176
131
  ```
177
132