What does `*prefect.core.flow.Flow.run_agent*` do?...
# prefect-community
s
What does
*prefect.core.flow.Flow.run_agent*
do? It's unclear from documentation and src code, which seems to say it runs an Agent from inside a Flow, which might be confusing since I was under the impression that Agent runs Flows, not the other way around.
discourse 1
a
Prefect Cloud is your orchestration layer or orchestration API telling agents what to do, when, and how. Agents are part of your execution layer, they are polling the orchestration API for work, executing the work, and reporting the state of it to the orchestration API. I don't think it's helpful for you to dive deep into how a flow run gets deployed to an agent under the hood. The best way when you're getting started is to start writing your flows and deploy them.
and you shouldn't start an agent from inside the flow because the agent must already exist so that it can pick up a flow run Usually here is how it works. You start by writing your flow - `yourflow.py`:
Copy code
from prefect import task, Flow


@task(log_stdout=True)
def hello_world():
    print("hello world")


with Flow("hello") as flow:
    hw = hello_world()
You start an agent from one terminal:
Copy code
prefect agent local start
Then in another terminal, you register your flow:
Copy code
prefect register --project xxx -p /path/to/yourflow.py
Then you can trigger a run on the agent:
Copy code
prefect run --project xxx --name yourflowname --watch
and then you should see that your agent picked up this flow run
k
Not super sure, but I don’t think that is hooked up anywhere
z
run_agent
isn’t recommended anymore, but it basically runs the agent inline instead of in a separate process as you would with
prefect agent local start
. It makes sure to include the labels that your flow would need to match.
👍 1
s
Perhaps let's deprecate?
z
We won’t be making any more breaking changes to the 1.x versions, so we can “deprecate” it but it’ll never be removed.
I agree an additional comment in the docstring would be nice at least 🙂