Task Management ExampleΒΆ
This guide provides a professional, step-by-step walkthrough for creating, registering, and executing a custom task using the TaskManager and Task classes from the agenticaiframework package. It is intended for developers who want to define reusable, modular units of work for their agents.
Enterprise Workflow Support
Part of 400+ modules with 12 workflow types including DAG orchestration and parallel execution. See Tasks Documentation.
Prerequisites & ConfigurationΒΆ
- Installation: Ensure
agenticaiframeworkis installed and accessible in your Python environment. - No additional configuration is required for this example.
- Python Version: Compatible with Python 3.10+.
CodeΒΆ
Step-by-Step ExecutionΒΆ
-
Import Required Classes Import
TaskManagerandTaskfromagenticaiframework.tasks. -
Instantiate the Task Manager Create an instance of
TaskManagerto handle task registration and execution. -
Define a Custom Task Create a class inheriting from
Taskand implement therunmethod with the desired logic. -
Create the Task Instance Instantiate your custom task with a unique name.
-
Register the Task Use
register_taskto add the task to the manager's registry. -
Execute the Task Call the
runmethod with the required arguments. -
List Registered Tasks Access the
taskslist to see all registered tasks. -
Retrieve a Specific Task Use
get_taskto fetch a task by name.
Best Practice: Keep tasks focused on a single responsibility to make them easier to test and reuse.
Expected InputΒΆ
No user input is required; the script uses hardcoded values for demonstration purposes. In production, task parameters could be dynamically generated from user input, workflows, or other runtime data.
Expected OutputΒΆ
How to RunΒΆ
Run the example from the project root:
| Bash | |
|---|---|
If installed as a package, you can also run it from anywhere:
| Bash | |
|---|---|
Tip: Combine
TaskManagerwithAgentManagerto assign and execute tasks dynamically within agents.