Dave Aitel
08/26/2024, 5:07 PMNate
08/26/2024, 5:09 PMresult_type=T
to tasksDave Aitel
08/26/2024, 5:12 PMclass PythonRunnerInput(BaseModel):
code: str = Field(..., description="The Python code to execute")
class PythonRunnerTool(BaseTool):
name = "PythonRunnerTool"
description = "Tool to execute Python code on our local box (not the target). Returns the STDOUT and STDERR from the executed Python. You have to print things out to see them!"
args_schema = PythonRunnerInput
def __init__(self):
super().__init__()
self.args_schema = PythonRunnerInput
Dave Aitel
08/26/2024, 5:12 PMDave Aitel
08/26/2024, 5:13 PMDave Aitel
08/26/2024, 5:13 PMNate
08/26/2024, 5:14 PMdef some_tool_that_runs_python(code: str) -> str:
"""useful description for llm"""
# impl of tool
Dave Aitel
08/26/2024, 5:15 PMDave Aitel
08/26/2024, 5:15 PMNate
08/26/2024, 5:15 PMAnnotated
on str
or yeah change in the input type to wrap it in a basemodel subclassDave Aitel
08/26/2024, 5:15 PMDave Aitel
08/26/2024, 5:16 PMDave Aitel
08/26/2024, 5:16 PMNate
08/26/2024, 5:17 PMdocker run -p 4200:4200 -d --rm prefecthq/prefect:3.0.0rc17-python3.12 -- prefect --no-prompt server start --host 0.0.0.0
Dave Aitel
08/26/2024, 5:17 PMDave Aitel
08/26/2024, 5:17 PMDave Aitel
08/26/2024, 5:18 PMDave Aitel
08/26/2024, 5:18 PMNate
08/26/2024, 5:24 PM_AnnotatedAlias
to be provided there, but actually i forgot there's the instructions
kwarg anyways, so we dont need Annotated
really
In [3]: Task("give me a joke", result_type=str, instructions="mitch hedburg style").run()
āā Agent: Marvin āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®
ā ā
ā I used to do drugs. I still do, but I used to, too. ā
ā ā
ā Would you like to hear another one? ā
ā ā
ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 12:23:09 PM āāÆ
āā Agent: Marvin āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®
ā ā
ā ā
Tool call: "mark_task_17b0d99a_successful" ā
ā ā
ā Tool args: {'result': 'I used to do drugs. I still do, but I used to, too.'} ā
ā ā
ā Tool result: Task 17b0d99a ("give me a joke") marked successful. ā
ā ā
ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 12:23:10 PM āāÆ
Out[3]: 'I used to do drugs. I still do, but I used to, too.'
where instead of annotating str
with mitch hedburg style
, i just put that in the instructions
so maybe instead you say like valid python code
or whatever you want your string to be?Nate
08/26/2024, 5:25 PMIn [4]: Task("give me a joke", result_type=Annotated[str, Field(description="mitch hedburg style")]).run()
Dave Aitel
08/26/2024, 5:26 PMDave Aitel
08/26/2024, 5:28 PMDave Aitel
08/26/2024, 5:28 PMDave Aitel
08/26/2024, 5:30 PMDave Aitel
08/26/2024, 5:30 PMNate
08/26/2024, 5:33 PMAnnotated
should work if you want to stick to the wrapper class
In [1]: from controlflow import Task
In [2]: from pydantic import BaseModel, Field
In [3]: from typing import Annotated
In [4]: class Recon(BaseModel):
...: report: Annotated[str, Field(description="report for next agent - talk like a pirate")]
...:
In [5]: Task("produce a report", result_type=Recon).run()
āā Agent: Marvin āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®
ā ā
ā Here is the report in a pirate style: ā
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā Ahoy, matey! Here's th' report ye be needin'. ā
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā Now, I'll mark this task as successful. ā
ā ā
ā ā
ā ā
Tool call: "mark_task_bbff7816_successful" ā
ā ā
ā Tool args: {'result': {'report': "Ahoy, matey! Here's th' report ye be needin'."}} ā
ā ā
ā Tool result: Task bbff7816 ("produce a report") marked successful. ā
ā ā
ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 12:33:40 PM āāÆ
Out[5]: Recon(report="Ahoy, matey! Here's th' report ye be needin'.")
Nate
08/26/2024, 5:35 PMAnnotated
bc you could just set the value to Field(description="...")
and itd be the same thing. annotated is more nice when you want to plug in a builtin type with some extra metadata someplace