Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Replace all worker_* with agent_* #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
39 changes: 26 additions & 13 deletions naptha_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ async def create(
naptha,
module_name,
agent_modules = None,
worker_nodes = None,
agent_nodes = None,
environment_modules = None,
environment_nodes = None
):
Expand All @@ -647,8 +647,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 @@ -704,7 +704,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 @@ -730,9 +730,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 @@ -874,7 +874,7 @@ def _parse_parameters(args):

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 @@ -952,15 +952,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 @@ -1269,9 +1269,22 @@ 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)
elif args.command == "run":
await run(naptha, args.agent, user_id, args.parameters, args.worker_nodes, args.tool_nodes, args.environment_nodes, args.kb_nodes, args.file, args.persona_modules)
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:
try:
parsed_params = json.loads(args.parameters)
except json.JSONDecodeError:
params = shlex.split(args.parameters)
parsed_params = {}
for param in params:
key, value = param.split('=')
parsed_params[key] = value
else:
parsed_params = None

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/modules/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