File size: 1,465 Bytes
3370983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import inspect
from langchain_core.tools import StructuredTool
from typing import Optional
from pathlib import Path

# Example tools
def add(a: float, b: float) -> float:
    """Add two numbers together."""
    return a + b

def multiply(a: float, b: float) -> float:
    """Multiply two numbers together."""
    return a * b

def divide(a: float, b: float) -> float:
    """Divide two numbers."""
    return a / b

def subtract(a: float, b: float) -> float:
    """Subtract two numbers."""
    return a - b

# Prompt creation
def create_default_prompt(

    tools: list,

    system_prompt: Optional[str] = None,

    base_prompt: str = "original.txt",

) -> str:
    template_path = Path(__file__).parent.parent / "prompts" / base_prompt
    template = template_path.read_text()

    tool_strings = []
    for t in tools:
        func = t.func if isinstance(t, StructuredTool) else t
        sig = inspect.signature(func)
        doc = (func.__doc__ or "").strip()
        tool_strings.append(
            f"def {func.__name__}{sig}:\n    \"\"\"{doc}\"\"\"\n    ..."
        )
    tools_str = "\n\n".join(tool_strings)

    prompt = template.replace("{tools}", tools_str)

    if system_prompt:
        prompt = f"{system_prompt}\n\n{prompt}"

    return prompt



if __name__ == "__main__":
    tools = [multiply, divide, subtract]
    print(create_default_prompt(tools, system_prompt="You are a coding agent."))