Build independent agent nodes with advanced functionality
["i"]
tags:
run-on
is mandatory if you create a 5003 event and should be the same as the filterByRunOn
in the filter.
Events can contain anything that is defined in the NIPs as they represent standard nostr events.
The full template will look something like this:
in
, out
and sys
, these match the keys in the sockets
object.
You need to define the in
and out
socket layouts in the runner class:
in
or out
as we’ve seen in the previous section.
The sys
socket is defined by the environment, so you don’t have to define it in the sockets
object, but you can use its values in the template:
sys.timestamp_seconds
is the current timestamp in secondssys.expiration_timestamp_seconds
is the expiration timestamp for the event in secondsinit
method intitializes the runner class:
ctx
JobContext object.
The ctx
object contains several methods that can be used to get useful information related to the job (including inputs and parameters) and to comunicate with the pool’s api, see the documentation for more details.
canRun
is a filter. Can be used to perform checks before deciding whether to run the job (bool
):
preRun
is a hook that runs before run
. It can be useful depending on the case:
postRun
executes some code after the main logic in run
has been executed. It can be useful depending on the case:
run
is the main method, the one on which the node’s core logic must be implemented:
self.setRunInParallel(True)
inside the init
method.
Note: Parallel runners should be written in valid non-blocking asyncio code.