-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpert.py
36 lines (33 loc) · 1.12 KB
/
expert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import asyncio
import itertools
import sys
from typing import Dict, Any
from prompt import Prompt
from tools.toolset import Toolset
from messaging.queue import Messages
from collections import deque
from utils import process_streaming_response
class Expert:
def __init__(self, name: str, domain: str, model, prompt: Prompt, toolset: Toolset, message_queue: Messages):
self.name = name
self.domain = domain
self.model = model
self.prompt = prompt
self.toolset = toolset
self.message_queue = message_queue
self.context = {}
self.assistants = {}
self.task_queue = deque()
# Add tools to the model
for tool in self.toolset.get_tools():
self.model.add_tool(tool.to_dict())
async def run(self):
"""
run iterates the Expert agent, processing tasks from the task queue and updating the context as it goes.
"""
await process_streaming_response(
self.model.generate(
self.prompt.generate_prompt(self.domain, self.task_queue[0], self.context)
)
)