inspection
Class info¶
🛈 DocStrings¶
_type_to_string
¶
Convert type to normalized string representation for comparison.
Source code in src/llmling_agent/utils/inspection.py
120 121 122 123 124 125 126 127 128 129 130 |
|
call_with_context
¶
call_with_context(
func: Callable[..., T], context: AgentContext[Any], **kwargs: Any
) -> T
Call function with appropriate context injection.
Handles: - Simple functions - Bound methods - Functions expecting AgentContext - Functions expecting context data
Source code in src/llmling_agent/utils/inspection.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
execute
async
¶
execute(
func: Callable[..., T | Awaitable[T]],
*args: Any,
use_thread: bool = False,
**kwargs: Any,
) -> T
Execute callable, handling both sync and async cases.
Source code in src/llmling_agent/utils/inspection.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
has_argument_type
¶
has_argument_type(
func: Callable[..., Any],
arg_type: type | str | UnionType | Sequence[type | str | UnionType],
include_return: bool = False,
) -> bool
Check if function has any argument of specified type(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
Function to check |
required |
arg_type
|
type | str | UnionType | Sequence[type | str | UnionType]
|
Type(s) to look for. Can be: - Single type (int, str, etc) - Union type (int | str) - Type name as string - Sequence of the above |
required |
include_return
|
bool
|
Whether to also check return type annotation |
False
|
Examples:
>>> def func(x: int | str, y: list[int]) -> None: ...
>>> has_argument_type(func, int | str) # True
>>> has_argument_type(func, int) # True
>>> has_argument_type(func, list) # True
>>> has_argument_type(func, float) # False
>>> has_argument_type(func, (int, str)) # True
Returns:
Type | Description |
---|---|
bool
|
True if any argument matches any of the target types |
Source code in src/llmling_agent/utils/inspection.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 |
|
has_return_type
¶
has_return_type(
func: Callable[..., Any], expected_type: type[T]
) -> TypeGuard[Callable[..., T | Awaitable[T]]]
Check if a function has a specific return type annotation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
Function to check |
required |
expected_type
|
type[T]
|
The type to check for |
required |
Returns:
Type | Description |
---|---|
TypeGuard[Callable[..., T | Awaitable[T]]]
|
True if function returns the expected type (or Awaitable of it) |
Source code in src/llmling_agent/utils/inspection.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
validate_import
¶
Check existence of module, showing helpful error if not installed.
Source code in src/llmling_agent/utils/inspection.py
210 211 212 213 214 215 216 217 |
|