MCPcopy Create free account
hub / github.com/AutoPackAI/autopack / Pack

Class Pack

autopack/pack.py:12–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class Pack(BaseModel):
13 class Config:
14 arbitrary_types_allowed = True
15
16 ## Required
17
18 # The name of the tool that will be provided to the LLM
19 name: ClassVar[str]
20 # The description of the tool which is passed to the LLM
21 description: ClassVar[str]
22
23 ## Optional
24
25 # Any pip packages this Pack depends on.
26 dependencies: ClassVar[Optional[list[str]]] = None
27 # A list of Pack IDs needed for this tool to function effectively (e.g. `write_file` depends on `read_file`)
28 depends_on: ClassVar[Optional[list[str]]] = None
29 # Enhances tool selection by grouping this tool with other tools of the same category
30 categories: ClassVar[Optional[list[str]]] = None
31 # If this tool has side effects that cannot be undone (e.g. sending an email)
32 reversible: ClassVar[bool] = True
33 # A Pydantic BaseModel describing the Pack's run arguments
34 args_schema: ClassVar[Optional[type[BaseModel]]] = None
35
36 llm: Optional[Callable[[str], str]] = Field(
37 None, description="A callable function to call an LLM (string in string out)"
38 )
39 allm: Union[None, Callable[[str], str], Coroutine[Any, Any, str]] = Field(
40 None, description="An asynchronous callable function to call an LLM (string in string out)"
41 )
42 config: PackConfig = Field(default_factory=PackConfig.global_config)
43
44 def __init__(self, **data):
45 super().__init__(**data)
46 if not self.config.filesystem_manager:
47 self.config.init_filesystem_manager()
48
49 if self.llm and not callable(self.llm):
50 raise TypeError(f"LLM object {self.llm} must be callable")
51
52 if self.allm and not iscoroutinefunction(self.allm):
53 raise TypeError(f"Async LLM object {self.llm} must be async and callable")
54
55 if self.name is None:
56 raise TypeError(f"Class {self.__class__.__name__} must define 'name' as a class variable")
57 if self.description is None:
58 raise TypeError(f"Class {self.__class__.__name__} must define 'description' as a class variable")
59
60 def run(self, *args, **kwargs) -> str:
61 """Execute the _run function of the subclass, verifying the arguments. (Will eventually do callbacks or some
62 such)
63
64 Args: **kwargs (dict): The arguments to pass to _run. Each key should be the name of an argument,
65 and the value should be the value of the argument.
66
67 Returns: The response from the _run function of the subclass
68 """
69 try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected