Skip to content

Commit

Permalink
Replacing the worker_* with agent_*
Browse files Browse the repository at this point in the history
  • Loading branch information
adi-kmt authored and richardblythman committed Dec 28, 2024
1 parent ed17721 commit 970b86a
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 58 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ naptha orchestrators -d orchestrator_name
You can download and install the modules for an orchestrator without running first using:

```bash
naptha create orchestrator:multiagent_chat --agent_modules "agent:simple_chat_agent,agent:simple_chat_agent" --worker_nodes "node.naptha.ai,node1.naptha.ai" --environment_modules "environment:groupchat_environment" --environment_nodes "node.naptha.ai"
naptha create orchestrator:multiagent_chat --agent_modules "agent:simple_chat_agent,agent:simple_chat_agent" --agent_nodes "node.naptha.ai,node1.naptha.ai" --environment_modules "environment:groupchat_environment" --environment_nodes "node.naptha.ai"
```

You can run the orchestrator module on hosted nodes using:

```bash
naptha run orchestrator:multiagent_chat -p "prompt='i would like to count up to ten, one number at a time. ill start. one.'" --worker_nodes "node.naptha.ai,node1.naptha.ai" --environment_nodes "node.naptha.ai"
naptha run orchestrator:multiagent_chat -p "prompt='i would like to count up to ten, one number at a time. ill start. one.'" --agent_nodes "node.naptha.ai,node1.naptha.ai" --environment_nodes "node.naptha.ai"
```

Or on local nodes:

```bash
naptha run orchestrator:multiagent_chat -p "prompt='i would like to count up to ten, one number at a time. ill start. one.'" --worker_nodes "localhost,localhost" --environment_nodes "localhost"
naptha run orchestrator:multiagent_chat -p "prompt='i would like to count up to ten, one number at a time. ill start. one.'" --agent_nodes "localhost,localhost" --environment_nodes "localhost"
```

```bash
naptha run orchestrator:babyagi -p "objective='Research the history of football'" --worker_nodes "node.naptha.ai,node1.naptha.ai"
naptha run orchestrator:babyagi -p "objective='Research the history of football'" --agent_nodes "node.naptha.ai,node1.naptha.ai"
```

```bash
Expand All @@ -216,7 +216,7 @@ Tesla stock was lower to start a new week of trading, falling as investors worry
News Summary 2:
Tesla faces growing competition and softening demand, impacting its stock price which is trading 43% below its all-time high. The company’s profitability is declining, with earnings per share shrinking 46% year-over-year in Q2 2024. Despite recent price cuts and a plan to produce a low-cost EV model, sales growth has decelerated. Tesla is also involved in autonomous self-driving software, humanoid robots, and solar energy, but these segments may take years to significantly impact revenue.
'" --worker_nodes "node.naptha.ai,node1.naptha.ai"
'" --agent_nodes "node.naptha.ai,node1.naptha.ai"
```

## Environment Modules
Expand Down
6 changes: 3 additions & 3 deletions naptha_sdk/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def __init__(self,
):
self.module_run = module_run
self.agent_index = agent_index
self.worker_node = Node(self.module_run.deployment.agent_deployments[self.agent_index].node)
self.agent_node = Node(self.module_run.deployment.agent_deployments[self.agent_index].node)

async def call_agent_func(self, *args, **kwargs):
logger.info(f"Running agent on worker node {self.worker_node.node_url}")
logger.info(f"Running agent on agent node {self.agent_node.node_url}")

agent_run_input = AgentRunInput(
consumer_id=self.module_run.consumer_id,
inputs=kwargs,
deployment=self.module_run.deployment.agent_deployments[self.agent_index].model_dump(),
)

agent_run = await self.worker_node.run_agent_in_node(agent_run_input)
agent_run = await self.agent_node.run_agent_in_node(agent_run_input)
return agent_run
24 changes: 12 additions & 12 deletions naptha_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ async def create(
naptha,
module_name,
agent_modules = None,
worker_nodes = None,
agent_nodes = None,
environment_modules = None,
environment_nodes = None
):
Expand All @@ -661,8 +661,8 @@ async def create(
AgentDeployment(
name=agent_module,
module={"name": agent_module},
node=url_to_node(worker_node)
) for agent_module, worker_node in zip(agent_modules or [], worker_nodes or [])
node=url_to_node(agent_node)
) for agent_module, agent_node in zip(agent_modules or [], agent_nodes or [])
],
"environment_deployments": [
EnvironmentDeployment(
Expand Down Expand Up @@ -718,7 +718,7 @@ async def run(
module_name,
user_id,
parameters=None,
worker_nodes=None,
agent_nodes=None,
tool_nodes=None,
environment_nodes=None,
kb_nodes=None,
Expand All @@ -744,9 +744,9 @@ async def run(

# Handle sub-deployments
agent_deployments = []
if worker_nodes:
for worker_node in worker_nodes:
agent_deployments.append(AgentDeployment(node=NodeSchema(ip=worker_node.strip())))
if agent_nodes:
for agent_node in agent_nodes:
agent_deployments.append(AgentDeployment(node=NodeSchema(ip=agent_node.strip())))
tool_deployments = []
if tool_nodes:
for tool_node in tool_nodes:
Expand Down Expand Up @@ -867,7 +867,7 @@ def _parse_list_arg(args, arg_name, default=None, split_char=','):

def _parse_str_args(args):
# Parse all list arguments
args.worker_nodes = _parse_list_arg(args, 'worker_nodes', default=None)
args.agent_nodes = _parse_list_arg(args, 'agent_nodes', default=None)
args.tool_nodes = _parse_list_arg(args, 'tool_nodes', default=None)
args.environment_nodes = _parse_list_arg(args, 'environment_nodes', default=None)
args.kb_nodes = _parse_list_arg(args, 'kb_nodes', default=None)
Expand Down Expand Up @@ -945,15 +945,15 @@ async def main():
create_parser = subparsers.add_parser("create", help="Execute create command.")
create_parser.add_argument("module", help="Select the module to create")
create_parser.add_argument("-a", "--agent_modules", help="Agent modules to create")
create_parser.add_argument("-n", "--worker_nodes", help="Agent nodes to take part in orchestrator runs.")
create_parser.add_argument("-n", "--agent_nodes", help="Agent nodes to take part in orchestrator runs.")
create_parser.add_argument("-e", "--environment_modules", help="Environment module to create")
create_parser.add_argument("-m", "--environment_nodes", help="Environment nodes to store data during agent runs.")

# Run command
run_parser = subparsers.add_parser("run", help="Execute run command.")
run_parser.add_argument("agent", help="Select the agent to run")
run_parser.add_argument("-p", '--parameters', type=str, help='Parameters in "key=value" format')
run_parser.add_argument("-n", "--worker_nodes", help="Worker nodes to take part in agent runs.")
run_parser.add_argument("-n", "--agent_nodes", help="Agent nodes to take part in agent runs.")
run_parser.add_argument("-t", "--tool_nodes", help="Tool nodes to take part in agent runs.")
run_parser.add_argument("-e", "--environment_nodes", help="Environment nodes to store data during agent runs.")
run_parser.add_argument('-k', '--kb_nodes', type=str, help='Knowledge base nodes')
Expand Down Expand Up @@ -1253,7 +1253,7 @@ async def main():
await list_kbs(naptha, args.kb_name)

elif args.command == "create":
await create(naptha, args.module, args.agent_modules, args.worker_nodes, args.environment_modules, args.environment_nodes)
await create(naptha, args.module, args.agent_modules, args.agent_nodes, args.environment_modules, args.environment_nodes)

elif args.command == "run":
if hasattr(args, 'parameters') and args.parameters is not None:
Expand All @@ -1268,7 +1268,7 @@ async def main():
else:
parsed_params = None

await run(naptha, args.agent, user_id, parsed_params, args.worker_nodes, args.tool_nodes, args.environment_nodes, args.kb_nodes, args.file, args.personas_urls)
await run(naptha, args.agent, user_id, parsed_params, args.agent_nodes, args.tool_nodes, args.environment_nodes, args.kb_nodes, args.file, args.personas_urls)
elif args.command == "inference":
request = ChatCompletionRequest(
messages=[{"role": "user", "content": args.prompt}],
Expand Down
54 changes: 27 additions & 27 deletions naptha_sdk/client/grpc_server_pb2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion naptha_sdk/client/grpc_server_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
from naptha_sdk.client import grpc_server_pb2 as grpc__server__pb2

GRPC_GENERATED_VERSION = '1.67.0'
GRPC_GENERATED_VERSION = '1.68.1'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

Expand Down
4 changes: 2 additions & 2 deletions naptha_sdk/client/naptha.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class Agent:
def __init__(self,
name,
fn,
worker_node_url,
agent_node_url,
):
self.name = name
self.fn = fn
self.worker_node_url = worker_node_url
self.agent_node_url = agent_node_url
self.repo_id = name
2 changes: 1 addition & 1 deletion naptha_sdk/client/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ async def run_agent_grpc(self, agent_run_input: AgentRunInput):
agent_deployment = grpc_server_pb2.AgentDeployment(
name=agent_run_input.deployment.name,
module=agent_module,
worker_node=agent_run_input.deployment.worker_node
node=agent_run_input.deployment.node
)

# Create request
Expand Down
6 changes: 3 additions & 3 deletions naptha_sdk/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@


class Flow:
def __init__(self, name, user_id, worker_nodes, agent_run_params):
def __init__(self, name, user_id, agent_nodes, agent_run_params):
self.name = name
self.user_id = user_id
self.worker_nodes = worker_nodes
self.agent_nodes = agent_nodes
self.agent_run_params = agent_run_params

flow_run_input = {
"agent_name": self.name,
"agent_run_params_type": "package",
"consumer_id": self.user_id,
"worker_nodes": [w.node_url for w in self.worker_nodes],
"agent_nodes": [w.node_url for w in self.agent_nodes],
"agent_run_params": self.agent_run_params,
}
self.flow_run = AgentRunInput(**flow_run_input)
Expand Down
8 changes: 4 additions & 4 deletions naptha_sdk/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Task:
def __init__(self,
name,
fn,
worker_node_url,
agent_node_url,
orchestrator_node,
flow_run,
cfg,
Expand All @@ -21,10 +21,10 @@ def __init__(self,
self.orchestrator_node = orchestrator_node
self.flow_run = flow_run
self.task_engine_cls = task_engine_cls
if isinstance(worker_node_url, str):
self.worker_node = self.node_url_to_node(worker_node_url, node_cls)
if isinstance(agent_node_url, str):
self.agent_node = self.node_url_to_node(agent_node_url, node_cls)
else:
self.worker_node = worker_node_url
self.agent_node = agent_node_url

async def __call__(self, *args, **kwargs):
return await run_task(
Expand Down

0 comments on commit 970b86a

Please sign in to comment.