Skip to content

Commit 7a28da8

Browse files
Merge pull request #9 from kevinbackhouse/yaml-headers
Add header to the yaml files
2 parents ee6f860 + 98b6015 commit 7a28da8

29 files changed

+162
-10
lines changed

available_tools.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
1+
import logging
2+
3+
class VersionException(Exception):
4+
pass
5+
6+
class FileTypeException(Exception):
7+
pass
8+
19
class AvailableTools:
210
"""
311
This class is used for storing dictionaries of all the available
412
personalities, taskflows, and prompts.
513
"""
6-
def __init__(self, personalities: dict, taskflows: dict, prompts: dict):
7-
self.personalities = personalities
8-
self.taskflows = taskflows
9-
self.prompts = prompts
14+
def __init__(self, yamls: dict):
15+
self.personalities = {}
16+
self.taskflows = {}
17+
self.prompts = {}
18+
self.toolboxes = {}
19+
20+
# Iterate through all the yaml files and divide them into categories.
21+
# Each file should contain a header like this:
22+
#
23+
# seclab-taskflow-agent:
24+
# type: taskflow
25+
# version: 1
26+
#
27+
for path, yaml in yamls.items():
28+
try:
29+
header = yaml['seclab-taskflow-agent']
30+
version = header['version']
31+
if version != 1:
32+
raise VersionException(str(version))
33+
filetype = header['type']
34+
if filetype == 'personality':
35+
self.personalities.update({path: yaml})
36+
elif filetype == 'taskflow':
37+
self.taskflows.update({path: yaml})
38+
elif filetype == 'prompt':
39+
self.prompts.update({path: yaml})
40+
elif filetype == 'toolbox':
41+
self.toolboxes.update({path: yaml})
42+
else:
43+
raise FileTypeException(str(filetype))
44+
except KeyError as err:
45+
logging.error(f'{path} does not contain the key {err.args[0]}')
46+
except VersionException as err:
47+
logging.error(f'{path}: seclab-taskflow-agent version {err.args[0]} is not supported')
48+
except FileTypeException as err:
49+
logging.error(f'{path}: seclab-taskflow-agent file type {err.args[0]} is not supported')

main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def parse_prompt_args(available_tools: AvailableTools,
7979
l = args[0].l
8080
return p, t, l, ' '.join(args[0].prompt), help_msg
8181

82-
async def deploy_task_agents(agents: dict,
82+
async def deploy_task_agents(available_tools: AvailableTools,
83+
agents: dict,
8384
prompt: str,
8485
async_task: bool = False,
8586
toolboxes_override: list = [],
@@ -120,7 +121,7 @@ async def deploy_task_agents(agents: dict,
120121
tool_filter = create_static_tool_filter(blocked_tool_names=blocked_tools) if blocked_tools else None
121122

122123
# fetch mcp params
123-
mcp_params = mcp_client_params(YamlParser('toolboxes').get_yaml_dict(recurse=True), toolboxes)
124+
mcp_params = mcp_client_params(available_tools.toolboxes, toolboxes)
124125
for tb, (params, confirms, server_prompt, client_session_timeout) in mcp_params.items():
125126
server_prompts.append(server_prompt)
126127
# https://openai.github.io/openai-agents-python/mcp/
@@ -401,6 +402,7 @@ async def on_handoff_hook(
401402
raise ValueError("No such personality!")
402403

403404
await deploy_task_agents(
405+
available_tools,
404406
{ p:personality },
405407
prompt,
406408
run_hooks=TaskRunHooks(
@@ -575,6 +577,7 @@ async def run_prompts(async_task=False, max_concurrent_tasks=5):
575577
async def _deploy_task_agents(resolved_agents, prompt):
576578
async with semaphore:
577579
result = await deploy_task_agents(
580+
available_tools,
578581
# pass agents and prompt by assignment, they change in-loop
579582
resolved_agents,
580583
prompt,
@@ -626,9 +629,10 @@ async def _deploy_task_agents(resolved_agents, prompt):
626629

627630
if __name__ == '__main__':
628631
available_tools = AvailableTools(
629-
personalities = YamlParser('personalities').get_yaml_dict(),
630-
taskflows = YamlParser('taskflows').get_yaml_dict(),
631-
prompts = YamlParser('prompts').get_yaml_dict(dir_namespace=True))
632+
YamlParser('personalities').get_yaml_dict() |
633+
YamlParser('taskflows').get_yaml_dict() |
634+
YamlParser('prompts').get_yaml_dict(dir_namespace=True) |
635+
YamlParser('toolboxes').get_yaml_dict(recurse=True))
632636

633637
p, t, l, user_prompt, help_msg = parse_prompt_args(available_tools)
634638

personalities/assistant.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
You are a helpful assistant.
37
task: |

personalities/c_auditer.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
Your name is Ronald. You are a C programming language security expert.
37
You have the ability to call tools to aid you in your security reviews.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
2-
You are an an apples expert.
6+
You are an apples expert.
37
48
task: |
59
Answer any questions about apples.

personalities/examples/banana_expert.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
You are a bananas expert.
37

personalities/examples/echo.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
You are a simple echo bot. You use echo tools to echo things.
37

personalities/examples/example_triage_agent.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
You are a triage agent. You route tasks to other agents.
37

personalities/examples/fruit_expert.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
Your name is Bob. You are a fruit expert.
37

personalities/examples/orange_expert.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
seclab-taskflow-agent:
2+
type: personality
3+
version: 1
4+
15
personality: |
26
You are an oranges expert.
37

0 commit comments

Comments
 (0)