Core
llm_expose.core.content_parts
¶
Utilities for OpenAI-compatible multimodal message content parts.
build_local_attachment_descriptor(path, *, kind, include_path, attachment_ref=None)
¶
Build a normalized descriptor for a local attachment path.
Source code in llm_expose/core/content_parts.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
build_user_content(text, *, image_urls=None, image_detail='auto')
¶
Build user content string or multimodal content list.
Source code in llm_expose/core/content_parts.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
content_has_images(content)
¶
Return True when content contains at least one image block.
Source code in llm_expose/core/content_parts.py
113 114 115 116 117 118 119 120 121 122 123 124 | |
extract_image_urls(content)
¶
Extract image URLs from OpenAI-style multimodal content parts.
Source code in llm_expose/core/content_parts.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
extract_invocation_attachments(content)
¶
Extract normalized attachment descriptors from user content blocks.
Source code in llm_expose/core/content_parts.py
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 70 71 | |
file_to_data_url(path)
¶
Convert a local file into a data URL for image_url blocks.
Source code in llm_expose/core/content_parts.py
199 200 201 202 203 204 205 206 207 | |
messages_have_images(messages)
¶
Return True when any message includes image blocks.
Source code in llm_expose/core/content_parts.py
127 128 129 130 131 132 | |
normalize_mcp_content(content)
¶
Normalize MCP content blocks into OpenAI-compatible text/image_url parts.
Source code in llm_expose/core/content_parts.py
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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
strip_image_parts(messages)
¶
Return a copy of messages with all image parts removed.
Returns:
| Type | Description |
|---|---|
tuple[list[Message], int]
|
A tuple of (new_messages, stripped_count). |
Source code in llm_expose/core/content_parts.py
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 | |
llm_expose.core.builtin_mcp
¶
Builtin in-process MCP tools for llm-expose.
BuiltinMCPClient
¶
Minimal in-process MCP-like client for builtin llm-expose tools.
Source code in llm_expose/core/builtin_mcp.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
ToolExecutionContext
dataclass
¶
Execution metadata passed to builtin MCP tools.
Source code in llm_expose/core/builtin_mcp.py
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 | |
to_public_dict()
¶
Return a JSON-serializable public view of the execution context.
Source code in llm_expose/core/builtin_mcp.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
llm_expose.core.tool_aware_completion
¶
Reusable tool-aware LLM completion handler (auto-execute mode).
ToolAwareCompletion
¶
Provider-agnostic tool-aware completion with automatic tool execution.
This handler executes all tool calls automatically without approval. For approval-based workflows, use Orchestrator's approval handlers.
Usage
async with ToolAwareCompletion(...) as handler: response = await handler.complete(messages)
Source code in llm_expose/core/tool_aware_completion.py
18 19 20 21 22 23 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 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 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 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 184 185 186 187 188 189 190 191 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 | |
__aenter__()
async
¶
Context manager entry: initialize runtime if we own it.
Source code in llm_expose/core/tool_aware_completion.py
71 72 73 74 75 | |
__aexit__(exc_type, exc_val, exc_tb)
async
¶
Context manager exit: shutdown runtime if we own it.
Source code in llm_expose/core/tool_aware_completion.py
77 78 79 80 | |
__init__(provider, mcp_config=None, mcp_runtime=None, requested_servers=None, timeout_seconds=30)
¶
Initialize tool-aware completion handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
BaseProvider
|
LLM provider (LiteLLM, etc.) |
required |
mcp_config
|
MCPConfig | None
|
MCP configuration (creates new runtime if provided) |
None
|
mcp_runtime
|
MCPRuntimeManager | None
|
Existing runtime (reuse if provided, e.g., from Orchestrator) |
None
|
requested_servers
|
list[str] | None
|
Filter to these server names (used with mcp_config) |
None
|
timeout_seconds
|
int
|
Tool execution timeout |
30
|
Note: Provide EITHER mcp_config OR mcp_runtime, not both.
Source code in llm_expose/core/tool_aware_completion.py
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 | |
complete(messages, *, execution_context=None, max_rounds=8)
async
¶
Execute tool-aware completion loop (auto-execute all tools).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation history (OpenAI format) |
required |
max_rounds
|
int
|
Maximum tool execution rounds |
8
|
Returns:
| Type | Description |
|---|---|
str
|
Final assistant response text |
Source code in llm_expose/core/tool_aware_completion.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 | |