Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions task_manager/byllm/BE/minimal_version/task_manager.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import from byllm.llm { Model }

glob llm = Model(model_name="gpt-4o", verbose=False);

node Task {
has task:str = "";
has date:str = "";
has time:str = "";
}

node TaskHandling {
def add_task(task: Task) -> str {
self ++> task;
return "Task added successfully";
}
def check_scheduled_tasks -> list[Task] {
self ++> Task(
task="Check scheduled tasks",
date="2025-10-10",
time="10:00:00"
); # Add a sample task for demonstration
return [self --> (`?Task)];
}
def extract_task_info(utterance: str) -> str by llm(
method="ReAct",
tools=([self.add_task])
);
def summarize_tasks() -> str by llm(
method="ReAct",
tools=([self.check_scheduled_tasks])
);
def route_and_run(utterance: str) -> str by llm(
method="ReAct",
tools=([self.extract_task_info, self.summarize_tasks])
);
can execute with task_manager entry {
print("[TaskHandling Node Activated]");
response = self.route_and_run(visitor.utterance);
print("→", response);
}
}

node EmailHandling {
def write_email_content(utterance: str) -> str by llm();
def route_and_run(utterance: str) -> str by llm(
method="ReAct",
tools=([self.write_email_content])
);
can execute with task_manager entry {
print("[EmailHandling Node Activated]");
response = self.route_and_run(visitor.utterance);
print("→", response);
}
}

node GeneralChat {
def chat(utterance: str) -> str by llm();
can execute with task_manager entry {
print("[GeneralChat Node Activated]");
response = self.chat(visitor.utterance);
print("→", response);
}
}

enum RoutingNodes{
TASK_HANDLING = "TaskHandling",
EMAIL_HANDLING = "EmailHandling",
GENERAL_CHAT = "GeneralChat"
Comment on lines +66 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think we need the = "TaskHandling" etc. Can just use comma's (The LLM will see the enum name).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I tested it without using these strings inside the Enum. But then it couldn't identify the exact routing node. @marsninja

}

walker task_manager {
has utterance: str = "";

def route_to_node(utterance: str) -> RoutingNodes by llm();
can execute with `root entry {
routed_node_name = self.route_to_node(self.utterance);

if routed_node_name == RoutingNodes.TASK_HANDLING {
routed_node = here ++> TaskHandling();
} elif routed_node_name == RoutingNodes.EMAIL_HANDLING {
routed_node = here ++> EmailHandling();
} elif routed_node_name == RoutingNodes.GENERAL_CHAT {
routed_node = here ++> GeneralChat();
}
visit routed_node;
}
}

with entry {
inputs: list = [
"Write an email to my friend which has the email [email protected] to inform that I need to arrange a meeting regarding the project.",
"Can you add a task to buy the Robotics items before tomorrow 12 noon",
"Summarize all my tasks",
"What was the popular programming language in 2020?"
];

for input in inputs {
print("User Input: " + input);
task_manager(utterance=input) spawn root;
print("====================================================================\n");
}
}