inspection
Class info¶
🛈 DocStrings¶
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
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
dataclasses_no_defaults_repr
¶
Exclude fields with values equal to the field default.
Source code in src/llmling_agent/utils/inspection.py
33 34 35 36 37 38 39 40 | |
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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
get_argument_key
¶
get_argument_key(
func: Callable[..., Any],
arg_type: type | str | UnionType | Sequence[type | str | UnionType],
include_return: bool = False,
) -> Literal[False] | str
Check if function has any argument of specified type(s) and return the key.
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]): ...
>>> get_argument_key(func, int | str) # Returns 'x'
>>> get_argument_key(func, int) # Returns 'x'
>>> get_argument_key(func, list) # Returns 'y'
>>> get_argument_key(func, float) # Returns False
>>> get_argument_key(func, (int, str)) # Returns 'x'
Returns:
| Type | Description |
|---|---|
Literal[False] | str
|
Parameter name (str) if a matching argument is found, False otherwise. |
Literal[False] | str
|
Only checks the origin type for generics, not type arguments |
Literal[False] | str
|
(e.g., list[int] matches 'list', but does not match 'int'). |
Source code in src/llmling_agent/utils/inspection.py
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 125 126 127 128 129 130 131 132 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 | |
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
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
is_async_callable
¶
Correctly check if a callable is async.
This function was copied from Starlette: https://github.com/encode/starlette/blob/78da9b9e218ab289117df7d62aee200ed4c59617/starlette/_utils.py#L36-L40
Source code in src/llmling_agent/utils/inspection.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
validate_import
¶
Check existence of module, showing helpful error if not installed.
Source code in src/llmling_agent/utils/inspection.py
269 270 271 272 273 274 275 276 | |