livellm 1.4.5__py3-none-any.whl → 1.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
livellm/livellm.py CHANGED
@@ -36,6 +36,7 @@ class BaseLivellmClient(ABC):
36
36
  model: str,
37
37
  messages: list,
38
38
  tools: Optional[list] = None,
39
+ include_history: bool = False,
39
40
  **kwargs
40
41
  ) -> AgentResponse:
41
42
  ...
@@ -53,6 +54,7 @@ class BaseLivellmClient(ABC):
53
54
  model: Optional[str] = None,
54
55
  messages: Optional[list] = None,
55
56
  tools: Optional[list] = None,
57
+ include_history: bool = False,
56
58
  **kwargs
57
59
  ) -> AgentResponse:
58
60
  """
@@ -69,7 +71,8 @@ class BaseLivellmClient(ABC):
69
71
  provider_uid="...",
70
72
  model="gpt-4",
71
73
  messages=[TextMessage(...)],
72
- tools=[]
74
+ tools=[],
75
+ include_history=False
73
76
  )
74
77
 
75
78
  Args:
@@ -79,6 +82,7 @@ class BaseLivellmClient(ABC):
79
82
  messages: List of messages
80
83
  tools: Optional list of tools
81
84
  gen_config: Optional generation configuration
85
+ include_history: Whether to include full conversation history in the response
82
86
 
83
87
  Returns:
84
88
  AgentResponse with the agent's output
@@ -103,7 +107,8 @@ class BaseLivellmClient(ABC):
103
107
  model=model,
104
108
  messages=messages,
105
109
  tools=tools or [],
106
- gen_config=kwargs or None
110
+ gen_config=kwargs or None,
111
+ include_history=include_history
107
112
  )
108
113
  return await self.handle_agent_run(agent_request)
109
114
 
@@ -122,6 +127,7 @@ class BaseLivellmClient(ABC):
122
127
  model: str,
123
128
  messages: list,
124
129
  tools: Optional[list] = None,
130
+ include_history: bool = False,
125
131
  **kwargs
126
132
  ) -> AsyncIterator[AgentResponse]:
127
133
  ...
@@ -139,6 +145,7 @@ class BaseLivellmClient(ABC):
139
145
  model: Optional[str] = None,
140
146
  messages: Optional[list] = None,
141
147
  tools: Optional[list] = None,
148
+ include_history: bool = False,
142
149
  **kwargs
143
150
  ) -> AsyncIterator[AgentResponse]:
144
151
  """
@@ -157,7 +164,8 @@ class BaseLivellmClient(ABC):
157
164
  provider_uid="...",
158
165
  model="gpt-4",
159
166
  messages=[TextMessage(...)],
160
- tools=[]
167
+ tools=[],
168
+ include_history=False
161
169
  ):
162
170
  ...
163
171
 
@@ -168,6 +176,7 @@ class BaseLivellmClient(ABC):
168
176
  messages: List of messages
169
177
  tools: Optional list of tools
170
178
  gen_config: Optional generation configuration
179
+ include_history: Whether to include full conversation history in the response
171
180
 
172
181
  Returns:
173
182
  AsyncIterator of AgentResponse chunks
@@ -192,7 +201,8 @@ class BaseLivellmClient(ABC):
192
201
  model=model,
193
202
  messages=messages,
194
203
  tools=tools or [],
195
- gen_config=kwargs or None
204
+ gen_config=kwargs or None,
205
+ include_history=include_history
196
206
  )
197
207
  stream = self.handle_agent_run_stream(agent_request)
198
208
 
@@ -1,7 +1,7 @@
1
1
  from .common import BaseRequest, ProviderKind, Settings, SuccessResponse
2
2
  from .fallback import AgentFallbackRequest, AudioFallbackRequest, TranscribeFallbackRequest, FallbackStrategy
3
3
  from .agent.agent import AgentRequest, AgentResponse, AgentResponseUsage
4
- from .agent.chat import Message, MessageRole, TextMessage, BinaryMessage
4
+ from .agent.chat import Message, MessageRole, TextMessage, BinaryMessage, ToolCallMessage, ToolReturnMessage
5
5
  from .agent.tools import Tool, ToolInput, ToolKind, WebSearchInput, MCPStreamableServerInput
6
6
  from .audio.speak import SpeakMimeType, SpeakRequest, SpeakStreamResponse
7
7
  from .audio.transcribe import TranscribeRequest, TranscribeResponse, File
@@ -27,6 +27,8 @@ __all__ = [
27
27
  "MessageRole",
28
28
  "TextMessage",
29
29
  "BinaryMessage",
30
+ "ToolCallMessage",
31
+ "ToolReturnMessage",
30
32
  "Tool",
31
33
  "ToolInput",
32
34
  "ToolKind",
@@ -1,5 +1,5 @@
1
1
  from .agent import AgentRequest, AgentResponse, AgentResponseUsage
2
- from .chat import Message, MessageRole, TextMessage, BinaryMessage
2
+ from .chat import Message, MessageRole, TextMessage, BinaryMessage, ToolCallMessage, ToolReturnMessage
3
3
  from .tools import Tool, ToolInput, ToolKind, WebSearchInput, MCPStreamableServerInput
4
4
 
5
5
 
@@ -11,6 +11,8 @@ __all__ = [
11
11
  "MessageRole",
12
12
  "TextMessage",
13
13
  "BinaryMessage",
14
+ "ToolCallMessage",
15
+ "ToolReturnMessage",
14
16
  "Tool",
15
17
  "ToolInput",
16
18
  "ToolKind",
@@ -2,7 +2,7 @@
2
2
 
3
3
  from pydantic import BaseModel, Field, field_validator
4
4
  from typing import Optional, List, Union
5
- from .chat import TextMessage, BinaryMessage
5
+ from .chat import TextMessage, BinaryMessage, ToolCallMessage, ToolReturnMessage
6
6
  from .tools import WebSearchInput, MCPStreamableServerInput
7
7
  from ..common import BaseRequest
8
8
 
@@ -12,6 +12,7 @@ class AgentRequest(BaseRequest):
12
12
  messages: List[Union[TextMessage, BinaryMessage]] = Field(..., description="The messages to use")
13
13
  tools: List[Union[WebSearchInput, MCPStreamableServerInput]] = Field(default_factory=list, description="The tools to use")
14
14
  gen_config: Optional[dict] = Field(default=None, description="The configuration for the generation")
15
+ include_history: bool = Field(default=False, description="Whether to include full conversation history in the response")
15
16
 
16
17
  class AgentResponseUsage(BaseModel):
17
18
  input_tokens: int = Field(..., description="The number of input tokens used")
@@ -19,4 +20,5 @@ class AgentResponseUsage(BaseModel):
19
20
 
20
21
  class AgentResponse(BaseModel):
21
22
  output: str = Field(..., description="The output of the response")
22
- usage: AgentResponseUsage = Field(..., description="The usage of the response")
23
+ usage: AgentResponseUsage = Field(..., description="The usage of the response")
24
+ history: Optional[List[Union[TextMessage, BinaryMessage, ToolCallMessage, ToolReturnMessage]]] = Field(default=None, description="Full conversation history including tool calls and returns (only included when include_history=true)")
@@ -7,6 +7,8 @@ class MessageRole(str, Enum):
7
7
  USER = "user"
8
8
  MODEL = "model"
9
9
  SYSTEM = "system"
10
+ TOOL_CALL = "tool_call"
11
+ TOOL_RETURN = "tool_return"
10
12
 
11
13
 
12
14
  class Message(BaseModel):
@@ -27,3 +29,13 @@ class BinaryMessage(Message):
27
29
  raise ValueError("MIME type are meant for user messages only")
28
30
  return self
29
31
 
32
+ class ToolCallMessage(Message):
33
+ """Message representing a tool call made by the agent"""
34
+ tool_name: str = Field(..., description="The name of the tool being called")
35
+ args: dict = Field(..., description="The arguments passed to the tool")
36
+
37
+ class ToolReturnMessage(Message):
38
+ """Message representing the return value from a tool call"""
39
+ tool_name: str = Field(..., description="The name of the tool that was called")
40
+ content: str = Field(..., description="The return value from the tool")
41
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: livellm
3
- Version: 1.4.5
3
+ Version: 1.5.2
4
4
  Summary: Python client for the LiveLLM Server
5
5
  Project-URL: Homepage, https://github.com/qalby-tech/livellm-client-py
6
6
  Project-URL: Repository, https://github.com/qalby-tech/livellm-client-py
@@ -257,6 +257,51 @@ response = await client.agent_run(
257
257
  )
258
258
  ```
259
259
 
260
+ #### Agent with Conversation History
261
+
262
+ You can request the full conversation history (including tool calls and returns) by setting `include_history=True`:
263
+
264
+ ```python
265
+ from livellm.models import TextMessage, ToolCallMessage, ToolReturnMessage
266
+
267
+ # Request with history enabled
268
+ response = await client.agent_run(
269
+ provider_uid="openai",
270
+ model="gpt-4",
271
+ messages=[TextMessage(role="user", content="Search for latest AI news")],
272
+ tools=[WebSearchInput(kind=ToolKind.WEB_SEARCH)],
273
+ include_history=True # Enable history in response
274
+ )
275
+
276
+ print(f"Output: {response.output}")
277
+
278
+ # Access full conversation history including tool interactions
279
+ if response.history:
280
+ for msg in response.history:
281
+ if isinstance(msg, TextMessage):
282
+ print(f"{msg.role}: {msg.content}")
283
+ elif isinstance(msg, ToolCallMessage):
284
+ print(f"Tool Call: {msg.tool_name}({msg.args})")
285
+ elif isinstance(msg, ToolReturnMessage):
286
+ print(f"Tool Return from {msg.tool_name}: {msg.content}")
287
+ ```
288
+
289
+ **History Message Types:**
290
+ - `TextMessage` - Regular text messages (user, model, system)
291
+ - `BinaryMessage` - Images or other binary content
292
+ - `ToolCallMessage` - Tool invocations made by the agent
293
+ - `tool_name` - Name of the tool called
294
+ - `args` - Arguments passed to the tool
295
+ - `ToolReturnMessage` - Results returned from tool calls
296
+ - `tool_name` - Name of the tool that was called
297
+ - `content` - The return value from the tool
298
+
299
+ **Use cases:**
300
+ - Debugging tool interactions
301
+ - Maintaining conversation state across multiple requests
302
+ - Auditing and logging complete conversations
303
+ - Building conversational UIs with full context visibility
304
+
260
305
  ### Audio Services
261
306
 
262
307
  #### Text-to-Speech
@@ -557,10 +602,12 @@ response = await client.ping()
557
602
  **Messages**
558
603
  - `TextMessage(role, content)` - Text message
559
604
  - `BinaryMessage(role, content, mime_type, caption?)` - Image/audio message
560
- - `MessageRole` - `USER` | `MODEL` | `SYSTEM` (or use strings: `"user"`, `"model"`, `"system"`)
605
+ - `ToolCallMessage(role, tool_name, args)` - Tool invocation by agent
606
+ - `ToolReturnMessage(role, tool_name, content)` - Tool execution result
607
+ - `MessageRole` - `USER` | `MODEL` | `SYSTEM` | `TOOL_CALL` | `TOOL_RETURN` (or use strings)
561
608
 
562
609
  **Requests**
563
- - `AgentRequest(provider_uid, model, messages, tools?, gen_config?)`
610
+ - `AgentRequest(provider_uid, model, messages, tools?, gen_config?, include_history?)` - Set `include_history=True` to get full conversation
564
611
  - `SpeakRequest(provider_uid, model, text, voice, mime_type, sample_rate, gen_config?)`
565
612
  - `TranscribeRequest(provider_uid, file, model, language?, gen_config?)`
566
613
  - `TranscriptionInitWsRequest(provider_uid, model, language?, input_sample_rate?, input_audio_format?, gen_config?)`
@@ -576,7 +623,7 @@ response = await client.ping()
576
623
  - `FallbackStrategy` - `SEQUENTIAL` | `PARALLEL`
577
624
 
578
625
  **Responses**
579
- - `AgentResponse(output, usage{input_tokens, output_tokens}, ...)`
626
+ - `AgentResponse(output, usage{input_tokens, output_tokens}, history?)` - `history` included when `include_history=True`
580
627
  - `TranscribeResponse(text, language)`
581
628
  - `TranscriptionWsResponse(transcription, is_end)` - Real-time transcription result
582
629
 
@@ -1,20 +1,20 @@
1
1
  livellm/__init__.py,sha256=p2Szx7PELGYi-PTnSNnRPGVbU438ZBTFXYAQoMToUfE,440
2
- livellm/livellm.py,sha256=McMt9OSME0Sr7NGpwqyr_VGEpXv4XcVb1EP-BwOuK0A,34092
2
+ livellm/livellm.py,sha256=d-1PlWKtMkw44575KZlhRr-c7p0B34W78F4PS_rhwUA,34598
3
3
  livellm/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  livellm/transcripton.py,sha256=WtL2PEFEVQ3RP2WOyjXqQFziQWKJvzJbG3T5cqfJ5qc,4187
5
- livellm/models/__init__.py,sha256=tCX_Q3ALjO0jbqhLFsVoITSm1AV--3pF5ZZc_l0VC1o,1447
5
+ livellm/models/__init__.py,sha256=4w8yDf_79kNwBfct-jHjAPNPxz4nFzMSWqlIo_7MFwc,1531
6
6
  livellm/models/common.py,sha256=nx0w7Th9xeHeQg6Ssxi7jEEh3aEcGyzGAP0uk9l072c,1772
7
7
  livellm/models/fallback.py,sha256=zGG_MjdbaTx0fqKZTEg3ullej-CJznPfwaon0jEvRvI,1170
8
8
  livellm/models/transcription.py,sha256=LQG5u7hgXuw6WyCxS-us0VGh9eky-f16JPpeT3jHULc,1608
9
9
  livellm/models/ws.py,sha256=OCoJwAjQLOz6ErTiTtb-qD22N4wSsEGvi_4JQqCHIPQ,1111
10
- livellm/models/agent/__init__.py,sha256=KVm6AgQoWEaoq47QAG4Ou4NimoXOTkjXC-0-gnMRLZ8,476
11
- livellm/models/agent/agent.py,sha256=-UcGv5Bzw5ALmWX4lIqpbWqMVjCsjBc0KIE6_JKbCXM,1106
12
- livellm/models/agent/chat.py,sha256=zGfeEHx0luwq23pqWF1megcuEDUl6IhV4keLJeZry_A,1028
10
+ livellm/models/agent/__init__.py,sha256=CvP3xzDAiBZ4giQZUBQsqAJd1rWO4cvHhqr2Oh346A0,560
11
+ livellm/models/agent/agent.py,sha256=qndsqcnX0MqbnblOA3niUWpU9873FU-PIH0vZkPoqAU,1504
12
+ livellm/models/agent/chat.py,sha256=WOs5h-D7hNsnucw6rxQkDCdHH2R5kiEe5kcmh25ivMU,1599
13
13
  livellm/models/agent/tools.py,sha256=wVWfx6_jxL3IcmX_Nt_PonZ3RQLtpfqJnszHz32BQiU,1403
14
14
  livellm/models/audio/__init__.py,sha256=sz2NxCOfFGVvp-XQUsdgOR_TYBO1Wb-8LLXaZDEiAZk,282
15
15
  livellm/models/audio/speak.py,sha256=lDITZ7fiLRuDhA-LxCPQ6Yraxr33B6Lg7VyR4CkuGk8,1872
16
16
  livellm/models/audio/transcribe.py,sha256=Leji2lk5zfq4GE-fw-z2dZR8BuijzW8TJ12GHw_UZJY,2085
17
- livellm-1.4.5.dist-info/METADATA,sha256=F7TfOu8TBhFuDXzwfRxWqerIvXYcS_irHy7zoMFaZ0A,18735
18
- livellm-1.4.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
19
- livellm-1.4.5.dist-info/licenses/LICENSE,sha256=yapGO2C_00ymEx6TADdbU8Oyc1bWOrZY-fjP-agmFL4,1071
20
- livellm-1.4.5.dist-info/RECORD,,
17
+ livellm-1.5.2.dist-info/METADATA,sha256=hg26D85D8M3JpnzeIW-Y-Ey3SkQz9yv9P_7FmzirfH4,20664
18
+ livellm-1.5.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
19
+ livellm-1.5.2.dist-info/licenses/LICENSE,sha256=yapGO2C_00ymEx6TADdbU8Oyc1bWOrZY-fjP-agmFL4,1071
20
+ livellm-1.5.2.dist-info/RECORD,,