Repository navigation
Your first flow
In this tutorial, you build a flow that reads the news each morning and writes a short brief. It takes about 15 minutes.
You learn how to:
- add nodes and connect them,
- give data from one node to the next,
- end a run with a report,
- run the flow on a schedule.
The flow has four nodes:
flowchart LR
news["🌐 news<br/><sub>Web request: read the feed</sub>"]
parse["⇄ parse<br/><sub>Convert: feed to JSON</sub>"]
summary["🤖 summary<br/><sub>Agent: write the brief</sub>"]
done["⏹ done<br/><sub>End: the report</sub>"]
news -- pass --> parse
parse -- pass --> summary
summary -- pass --> done
- Do the steps in Get started. You need an agent and a project.
- Know the words flow, node, outcome, and template. How Night Shift works tells them.
The project can be a project without a folder. This flow writes no files.
- Open your project, then its Flows page.
- Choose New flow.
- Type the name
morning-news, and confirm.
The editor opens. The flow has one Agent node. You use it later.
A Web request reads a web address and gives the answer as data.
- Click an empty spot of the canvas and press Tab. A search opens.
- Type
web, and pick Web request. - In the panel on the right, click the id under the title. Change it to
news. - Keep Method at
GET. - In URL, type the address of a news feed, for example
https://feeds.bbci.co.uk/news/world/rss.xml. Any RSS or Atom feed works. - Choose the ▶ button at the top of the panel (Start the run here). The run now starts at
news.
A feed is XML text. A Convert node turns it into a list of items that an agent can read.
- Keep
newsselected. - Press Tab, type
convert, and pick Convert. The new node goes afternews, with an edge from itspassoutcome. - Change its id to
parse. - Set Convert to RSS or Atom feed to JSON.
- Make sure that Value is
{{news.body}}. This template gives the body of the answer ofnews.
Each item now has a title, a link, and a summary. A later node reads the list as {{parse.data.items}}.
-
Select the Agent node that the flow came with. Change its id to
summary. -
In Profile, choose one of your profiles.
-
In Prompt, type:
These are the news items of today, as JSON: {{parse.data.items}} Pick the five items that matter most. Write a short brief in Markdown. Give each item one line and its link. Do not add an introduction. -
Connect
parsetosummary. Drag from thepassdot ofparsetosummary.
When the step ends, {{summary.output}} holds the brief.
An End node ends the run. Its report shows on Home, so you can read the brief there.
- Click an empty spot of the canvas and press Tab. Type
end, and pick End. - Change its id to
done. - Set Result to Done.
- In Message, type
The news brief is ready. - Set Report to Write it. In Text, type
{{summary.output}}. - Connect
summarytodone. Drag from thepassdot ofsummarytodone.
Look at Issues at the bottom of the canvas. When it shows no errors, the flow is ready. The editor saves each change for you.
- Choose Run at the top of the editor.
- Choose Start. The run page opens, and shows each step live.
The agent step takes a minute or two. When the run ends, the run page shows the report. Home shows it under What came out.
If the run fails, choose Ask why. An agent reads the run, and tells you what went wrong and what you can do.
- Go to the Flows page.
- On the card of
morning-news, open the ⋯ menu and choose Schedules. - Choose Add schedule.
- Choose At set times. Choose Every day, and set the time to
07:00. - Choose Add schedule.
Night Shift now runs the flow each morning, and the brief waits for you on Home.
A schedule runs only while Night Shift runs. When your computer sleeps at 07:00, the run starts when the computer wakes. After the late window of the schedule (15 minutes by default), Night Shift skips that day. To run schedules on a server that is always on, see Computers and Hosts.
Each of these steps teaches one more node.
A morning brief must not repeat the news of yesterday. A Since last run node remembers the items it saw, and gives only the new ones.
- Select
parse. Press Tab, typesince, and pick Since last run. Change its id tofresh. - Set Watch to A list. Set List to
{{parse.data.items}}, and Key tolink. - Connect its
newoutcome tosummary. Remove the old edge fromparsetosummary. - In the prompt of
summary, change{{parse.data.items}}to{{fresh.data.new}}.
When nothing is new, the node ends on same. That outcome has no edge, so the run ends there, and no agent runs. On the first run, every item is new.
To post the brief in a chat channel, use the kit kit:message/send. It sends a message to the incoming webhook of Slack, Discord, or ntfy. See Send a message.
A sent message cannot come back. When other people read the channel, put a Gate before the send:
- Add a Gate after
summary, with two options:sendandskip. - Connect
sendto the Subflow that runskit:message/send.
The Gate shows in your inbox. The message goes out only when you choose send.
You can also describe a flow, and let an agent draw it. Open a new flow, and type in the chat beside the canvas: "Each morning, read this feed, and write a brief of the five most important items." Check each proposed change, then choose Apply. See Build a flow with an agent.
- Flows and nodes tells every node type.
- Ideas lists flows that nobody has built yet.
- Gates and the inbox tells how to answer what waits for you.
This wiki comes from docs/wiki/ in the repository. To change a page, open a pull request there. An edit made here is lost at the next publish.
Start here
Use Night Shift
Reference
Repository