Repository navigation
Expand file tree
/
Copy pathtypes.py
More file actions
91 lines (65 loc) · 2.42 KB
/
Copy pathtypes.py
File metadata and controls
91 lines (65 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
"""Pure domain types shared across the whole system.
These carry no behaviour and no I/O — they are the vocabulary every layer
(harness, tools, frontends, adapters) speaks. Keeping them dependency-free is
what lets the ``core`` package sit at the bottom of the import graph.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
from typing import Any
class Role(str, Enum):
"""Author of a conversation message."""
SYSTEM = "system"
USER = "user"
ASSISTANT = "assistant"
TOOL = "tool"
@dataclass
class ToolCall:
"""A model's request to invoke one tool.
``arguments`` is the already-parsed JSON object the model emitted; adapters
are responsible for turning provider-specific payloads into this shape.
"""
id: str
name: str
arguments: dict[str, Any] = field(default_factory=dict)
@dataclass
class ToolResult:
"""Tool response text and the tables whose columns appear in that text."""
call_id: str
content: str
is_error: bool = False
tables_with_columns: tuple[str, ...] = ()
stop_turn: bool = False
@dataclass
class Message:
"""One entry in a conversation transcript.
A single assistant turn may both say something (``content``) and request
tools (``tool_calls``). Tool-role messages carry ``tool_call_id`` to bind
their result back to the originating call.
"""
role: Role
content: str = ""
tool_calls: list[ToolCall] = field(default_factory=list)
tool_call_id: str | None = None
name: str | None = None
# Frontends may persist one sanitized clarification for exactly the next
# user turn. It is provider-visible but removed by the next compression.
transient: bool = False
@dataclass
class ToolSpec:
"""Catalog entry the harness advertises to the LLM.
``parameters`` is a JSON-Schema object describing the tool's arguments,
matching what tool-calling LLM APIs expect.
"""
name: str
description: str
parameters: dict[str, Any] = field(default_factory=dict)
@dataclass
class Completion:
"""What an :class:`~lang2sql.core.ports.llm.LLMPort` returns for one call.
Either ``content`` (final answer) or ``tool_calls`` (the model wants to act)
or both. The agent loop branches on whether ``tool_calls`` is non-empty.
"""
content: str = ""
tool_calls: list[ToolCall] = field(default_factory=list)
finish_reason: str | None = None