decorators
hook
Source code in agenty/decorators.py
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
input(func)
staticmethod
Decorator to register a method as an input hook. It provides a simple way to designate methods that handle input processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[HookParam, AgentInputT]
|
The function to be registered as an input hook. |
required |
Returns:
| Type | Description |
|---|---|
Callable[HookParam, AgentInputT]
|
The original function, marked as an input hook. |
Example
class MyAgent(Agent[str, str]):
@hook.input
def process_input(self, input: str) -> str:
return input.upper()
Source code in agenty/decorators.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
output(func)
staticmethod
Decorator to register a method as an output hook. It provides a simple way to designate methods that handle output processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[HookParam, AgentOutputT]
|
The function to be registered as an output hook. |
required |
Returns:
| Type | Description |
|---|---|
Callable[HookParam, AgentOutputT]
|
The original function, marked as an output hook. |
Example
class MyAgent(Agent[str, str]):
@hook.output
def process_output(self, output: str) -> str:
return output.lower()
Source code in agenty/decorators.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
tool(func)
Decorator to register a method as an agent tool.
This decorator marks a method as a tool that can be called by the agent during execution. It handles proper type casting and logging of tool invocations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[ToolParams, AgentOutputT]
|
The function to be registered as a tool. Must be a method of an Agent subclass with proper type annotations. |
required |
Returns:
| Type | Description |
|---|---|
Callable[ToolParams, AgentOutputT]
|
A wrapped function that maintains the original function's type signature |
Callable[ToolParams, AgentOutputT]
|
while providing tool registration and logging functionality. |
Example
class MyAgent(Agent[str, str]):
@tool
def my_tool(self, param: str) -> str:
return f"Processed {param}"
Source code in agenty/decorators.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |