ruDra2916/KnowSphere
0
1# agents.py
2
3import uuid
4from contextlib import contextmanager
5from typing import Callable, Any
6import functools
7import asyncio
8
9
10# Simulated trace functionality
11def gen_trace_id() -> str:
12 return str(uuid.uuid4())
13
14@contextmanager
15def trace(name: str, trace_id: str = None):
16 print(f"[TRACE START] {name} - Trace ID: {trace_id}")
17 yield
18 print(f"[TRACE END] {name} - Trace ID: {trace_id}")
19
20
21# Simulated Agent class
22class Agent:
23 def __init__(self, name, instructions, tools=None, model=None, output_type=None, model_settings=None):
24 self.name = name
25 self.instructions = instructions
26 self.tools = tools or []
27 self.model = model
28 self.output_type = output_type
29 self.model_settings = model_settings
30
31 async def __call__(self, input_text: str):
32 print(f"[{self.name}] executing on input: {input_text}")
33 return f"[Simulated output for: {input_text}]"
34
35
36# Dummy Runner for running agents
37class Runner:
38 @staticmethod
39 async def run(agent: Agent, input_text: str):
40 print(f"Running {agent.name} with input:\n{input_text}\n")
41 class DummyResult:
42 def final_output_as(self, _):
43 return agent.output_type()
44 @property
45 def final_output(self):
46 return "[Simulated final output]"
47 return DummyResult()
48
49
50# Simulated decorator
51def function_tool(func: Callable) -> Callable:
52 @functools.wraps(func)
53 def wrapper(*args, **kwargs):
54 print(f"Function tool called: {func.__name__}")
55 return func(*args, **kwargs)
56 return wrapper
57
58
59# Simulated WebSearchTool
60class WebSearchTool:
61 def __init__(self, search_context_size="low"):
62 self.context_size = search_context_size
63
64
65# Simulated model settings
66class ModelSettings:
67 def __init__(self, tool_choice=None):
68 self.tool_choice = tool_choice
69 