Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Tools registered from an MCP server (via `.register_mcp_tools_stdio_async()`, `.register_mcp_tools_http_stream_async()`, or `Tool.from_mcp()`) now pass the tool result's `_meta` through to the `ContentToolResult`'s `extra` field. This lets MCP servers attach client-only metadata that isn't sent to the model — for example, shinychat's `display` hints, so a server can ask compatible chat UIs to open the tool-result card by default. Errored results still raise and never surface `_meta`.
* MCP tool results that carry `structuredContent` now use it as the tool result's value (JSON-dumped for the model), instead of dropping it. The converted content blocks are preserved client-side under the `extra["content"]` key, merged with the `_meta` passthrough described above.
* Providers now expose a `base_url` attribute (`chat.provider.base_url`) reporting the endpoint requests are sent to, when the provider can determine it. This is groundwork for richer telemetry (e.g. OpenTelemetry `server.address`/`server.port` attributes) and is handy for confirming which endpoint a provider resolved.
* The OpenTelemetry integration now emits **metrics** alongside spans, following the [GenAI semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/): per-request inference duration and token-usage histograms (`gen_ai.client.inference.*`), cumulative token-usage counters (including cache-read and reasoning tokens, broken down by `gen_ai.token.modality`), streaming latency (`gen_ai.client.inference.time_to_first_chunk`, `gen_ai.client.inference.time_per_output_chunk`), tool execution duration (`gen_ai.execute_tool.duration`), and per-invocation agent metrics (`gen_ai.invoke_agent.duration`, `gen_ai.invoke_agent.inference_calls`, `gen_ai.invoke_agent.tool_calls`). Metrics flow through the same SDK configuration as traces, so no extra setup is needed.
* OpenTelemetry spans are richer and more accurate. Chat spans now record `server.address`/`server.port`, the request parameters actually sent (`gen_ai.request.*`, including `gen_ai.request.stream` and reasoning effort), the finish reason (`gen_ai.response.finish_reasons`), cache-read and reasoning token counts, time to first chunk, and (with content capture enabled) the tool definitions sent with the request. The `invoke_agent` span is now an `internal`-kind span and records duration, inference/tool call counts, and total token usage. Successful requests are now marked with an `OK` span status (previously unset), and failed, cancelled (`StreamController.cancel()`), and interrupted (e.g. abandoned streams) requests now report an error status and `error.type` on both the spans and the duration metrics, matching ellmer.
* The result of `chat.files.get()` (and elements of `chat.files.list()`) can now be passed straight to `.chat()` (and anywhere else content is accepted), so a file uploaded in an earlier session can be reused from its id alone: `chat.chat("Summarize this.", chat.files.get("file_011CRabc..."))`. When the provider doesn't report a MIME type (OpenAI's Files API never does), it's guessed from the filename. For when you want the underlying `ContentUploaded` reference itself (e.g. to build a `UserTurn` by hand), `FileMetadata` gains a `.to_content()` method. This works via a new general convention: any object implementing `to_content() -> Content` (see `chatlas.types.SupportsContent`) is accepted anywhere content is passed, so third-party packages can make their own objects usable as chat inputs. (#417)

### Changes
Expand Down
284 changes: 244 additions & 40 deletions chatlas/_chat.py

Large diffs are not rendered by default.

Loading
Loading