lite-agent 0.1.0__py3-none-any.whl → 0.3.0__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.

Potentially problematic release.


This version of lite-agent might be problematic. Click here for more details.

@@ -1,166 +0,0 @@
1
- from collections.abc import AsyncGenerator
2
- from typing import Literal, TypedDict
3
-
4
- import litellm
5
- from funcall import Funcall
6
-
7
- from open_agents.loggers import logger
8
- from open_agents.processors import StreamChunkProcessor
9
- from open_agents.processors.stream_chunk_processor import AssistantMessage
10
-
11
-
12
- class LiteLLMRawChunk(TypedDict):
13
- """
14
- Define the type of chunk
15
- """
16
-
17
- type: Literal["litellm_raw"]
18
- raw: litellm.ModelResponseStream
19
-
20
-
21
- class UsageChunk(TypedDict):
22
- """
23
- Define the type of usage info chunk
24
- """
25
-
26
- type: Literal["usage"]
27
- usage: litellm.Usage
28
-
29
-
30
- class FinalMessageChunk(TypedDict):
31
- """
32
- Define the type of final message chunk
33
- """
34
-
35
- type: Literal["final_message"]
36
- message: AssistantMessage
37
- finish_reason: Literal["stop", "tool_calls"]
38
-
39
-
40
- class ToolCallChunk(TypedDict):
41
- """
42
- Define the type of tool call chunk
43
- """
44
-
45
- type: Literal["tool_call"]
46
- name: str
47
- arguments: str
48
-
49
-
50
- class ToolCallResultChunk(TypedDict):
51
- """
52
- Define the type of tool call result chunk
53
- """
54
-
55
- type: Literal["tool_call_result"]
56
- tool_call_id: str
57
- name: str
58
- content: str
59
-
60
-
61
- class ContentDeltaChunk(TypedDict):
62
- """
63
- Define the type of message chunk
64
- """
65
-
66
- type: Literal["content_delta"]
67
- delta: str
68
-
69
-
70
- class ToolCallDeltaChunk(TypedDict):
71
- """
72
- Define the type of tool call delta chunk
73
- """
74
-
75
- type: Literal["tool_call_delta"]
76
- tool_call_id: str
77
- name: str
78
- arguments_delta: str
79
-
80
-
81
- AgentChunk = LiteLLMRawChunk | UsageChunk | FinalMessageChunk | ToolCallChunk | ToolCallResultChunk | ContentDeltaChunk
82
-
83
-
84
- async def chunk_handler(
85
- resp: litellm.CustomStreamWrapper,
86
- fc: Funcall,
87
- ) -> AsyncGenerator[AgentChunk, None]:
88
- """
89
- Optimized chunk handler
90
-
91
- Args:
92
- resp: LiteLLM streaming response wrapper
93
- fc: function call handler
94
-
95
- Yields:
96
- litellm.ModelResponseStream: processed response chunk
97
-
98
- Raises:
99
- Exception: various exceptions during processing
100
- """
101
- processor = StreamChunkProcessor(fc)
102
- async for chunk in resp:
103
- if not isinstance(chunk, litellm.ModelResponseStream):
104
- logger.debug("unexpected chunk type: %s", type(chunk))
105
- logger.debug("chunk content: %s", chunk)
106
- continue
107
-
108
- # Handle usage info
109
- if usage := processor.handle_usage_info(chunk):
110
- yield UsageChunk(type="usage", usage=usage)
111
- continue
112
-
113
- # Get choice and delta data
114
- if not chunk.choices:
115
- yield LiteLLMRawChunk(type="litellm_raw", raw=chunk)
116
- continue
117
-
118
- choice = chunk.choices[0]
119
- delta = choice.delta
120
- if not processor.current_message:
121
- processor.initialize_message(chunk, choice)
122
- if delta.content:
123
- yield ContentDeltaChunk(type="content_delta", delta=delta.content)
124
- processor.update_content(delta.content)
125
- processor.update_tool_calls(delta.tool_calls)
126
- if delta.tool_calls:
127
- for tool_call in delta.tool_calls:
128
- if tool_call.function.arguments:
129
- yield ToolCallDeltaChunk(
130
- type="tool_call_delta",
131
- tool_call_id=processor.current_message.tool_calls[-1].id,
132
- name=processor.current_message.tool_calls[-1].function.name,
133
- arguments_delta=tool_call.function.arguments,
134
- )
135
- # Check if finished
136
- if choice.finish_reason and processor.current_message:
137
- current_message = processor.finalize_message()
138
- yield FinalMessageChunk(type="final_message", message=current_message, finish_reason=choice.finish_reason)
139
- # New: check tool_calls and handle
140
- tool_calls = current_message.tool_calls
141
- if tool_calls:
142
- # Execute each tool_call and yield result
143
- for tool_call in tool_calls:
144
- try:
145
- yield ToolCallChunk(
146
- type="tool_call",
147
- name=tool_call.function.name,
148
- arguments=tool_call.function.arguments,
149
- )
150
- content = await fc.call_function_async(tool_call.function.name, tool_call.function.arguments)
151
- yield ToolCallResultChunk(
152
- type="tool_call_result",
153
- tool_call_id=tool_call.id,
154
- name=tool_call.function.name,
155
- content=str(content),
156
- )
157
- except Exception as e: # noqa: PERF203
158
- logger.exception("Tool call %s failed", tool_call.id)
159
- yield ToolCallResultChunk(
160
- type="tool_call_result",
161
- tool_call_id=tool_call.id,
162
- name=tool_call.function.name,
163
- content=str(e),
164
- )
165
- continue
166
- yield LiteLLMRawChunk(type="litellm_raw", raw=chunk)
lite_agent/types.py DELETED
@@ -1,152 +0,0 @@
1
- from typing import Literal, TypedDict
2
-
3
- import litellm
4
- from pydantic import BaseModel
5
-
6
-
7
- class ToolCallFunction(BaseModel):
8
- name: str
9
- arguments: str | None = None
10
-
11
-
12
- class ToolCall(BaseModel):
13
- type: Literal["function"]
14
- function: ToolCallFunction
15
- id: str
16
-
17
-
18
- class AssistantMessage(BaseModel):
19
- id: str
20
- role: Literal["assistant"] = "assistant"
21
- content: str = ""
22
- tool_calls: list[ToolCall] | None = None
23
-
24
-
25
- class Message(TypedDict):
26
- role: str
27
- content: str
28
-
29
-
30
- class UserMessageContentItemText(TypedDict):
31
- type: Literal["text"]
32
- text: str
33
-
34
-
35
- class UserMessageContentItemImageURLImageURL(TypedDict):
36
- url: str
37
-
38
-
39
- class UserMessageContentItemImageURL(TypedDict):
40
- type: Literal["image_url"]
41
- image_url: UserMessageContentItemImageURLImageURL
42
-
43
-
44
- class AgentUserMessage(TypedDict):
45
- role: Literal["user"] = "user"
46
- content: str | list[UserMessageContentItemText | UserMessageContentItemImageURL]
47
-
48
-
49
- class AssistantMessageToolCallFunction(TypedDict):
50
- name: str
51
- arguments: str
52
-
53
-
54
- class AssistantMessageToolCall(TypedDict):
55
- id: str
56
- type: Literal["function"]
57
- function: AssistantMessageToolCallFunction
58
- tool_call_id: str
59
-
60
-
61
- class AgentAssistantMessage(TypedDict):
62
- role: Literal["assistant"] = "assistant"
63
- content: str
64
- tool_calls: list[AssistantMessageToolCall] | None
65
-
66
-
67
- class AgentSystemMessage(TypedDict):
68
- role: Literal["system"] = "system"
69
- content: str
70
-
71
-
72
- class AgentToolCallMessage(TypedDict):
73
- role: Literal["tool"] = "tool"
74
- tool_call_id: str
75
- content: str
76
-
77
-
78
- RunnerMessage = AgentUserMessage | AgentAssistantMessage | AgentToolCallMessage
79
- AgentMessage = RunnerMessage | AgentSystemMessage
80
- RunnerMessages = list[RunnerMessage]
81
-
82
-
83
- class LiteLLMRawChunk(TypedDict):
84
- """
85
- Define the type of chunk
86
- """
87
-
88
- type: Literal["litellm_raw"]
89
- raw: litellm.ModelResponseStream
90
-
91
-
92
- class UsageChunk(TypedDict):
93
- """
94
- Define the type of usage info chunk
95
- """
96
-
97
- type: Literal["usage"]
98
- usage: litellm.Usage
99
-
100
-
101
- class FinalMessageChunk(TypedDict):
102
- """
103
- Define the type of final message chunk
104
- """
105
-
106
- type: Literal["final_message"]
107
- message: AssistantMessage
108
- finish_reason: Literal["stop", "tool_calls"]
109
-
110
-
111
- class ToolCallChunk(TypedDict):
112
- """
113
- Define the type of tool call chunk
114
- """
115
-
116
- type: Literal["tool_call"]
117
- name: str
118
- arguments: str
119
-
120
-
121
- class ToolCallResultChunk(TypedDict):
122
- """
123
- Define the type of tool call result chunk
124
- """
125
-
126
- type: Literal["tool_call_result"]
127
- tool_call_id: str
128
- name: str
129
- content: str
130
-
131
-
132
- class ContentDeltaChunk(TypedDict):
133
- """
134
- Define the type of message chunk
135
- """
136
-
137
- type: Literal["content_delta"]
138
- delta: str
139
-
140
-
141
- class ToolCallDeltaChunk(TypedDict):
142
- """
143
- Define the type of tool call delta chunk
144
- """
145
-
146
- type: Literal["tool_call_delta"]
147
- tool_call_id: str
148
- name: str
149
- arguments_delta: str
150
-
151
-
152
- AgentChunk = LiteLLMRawChunk | UsageChunk | FinalMessageChunk | ToolCallChunk | ToolCallResultChunk | ContentDeltaChunk | ToolCallDeltaChunk
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: lite-agent
3
- Version: 0.1.0
4
- Summary: A lightweight, extensible framework for building AI agent.
5
- Author-email: Jianqi Pan <jannchie@gmail.com>
6
- License: MIT
7
- Keywords: AI,agent framework,assistant,chatbot,function call,openai,pydantic,rich,tooling
8
- Classifier: Intended Audience :: Developers
9
- Classifier: Intended Audience :: Science/Research
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Topic :: Communications :: Chat
17
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
- Requires-Python: >=3.10
20
- Requires-Dist: funcall>=0.6.0
21
- Requires-Dist: prompt-toolkit>=3.0.51
22
- Requires-Dist: rich>=14.0.0
@@ -1,13 +0,0 @@
1
- lite_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- lite_agent/__main__.py,sha256=D4Yg5a6hDYMq6aCEGg3MjILF4pVWD6mBKjri-qs7Rzk,3766
3
- lite_agent/agent.py,sha256=LmC5aqMVWsq5AkE18Od0FEVUdiZN1GTs5OlO6mrvxUM,1187
4
- lite_agent/chunk_handler.py,sha256=MDk9rW_axZ412VOPnITbQGVr-mCGAe2jy3khUXkYbvM,5135
5
- lite_agent/loggers.py,sha256=0-yb_1Ec8TodfTI_nZWeCJSpSZZM9R53UUOE5--L2iw,57
6
- lite_agent/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- lite_agent/runner.py,sha256=TaBm6pCFwdJtygNnmVZDlFbkK3-Z1s52YD9XviwrA6o,2257
8
- lite_agent/types.py,sha256=NUpoSDaaiWWYezWluDdWBb-DsYFvZFoNd4tLWqBzCZ4,3058
9
- lite_agent/processors/__init__.py,sha256=AIxxS9uLcNws1Erf-b8z8zZKaKA5NQ7ooZ7HaCIJTq4,115
10
- lite_agent/processors/stream_chunk_processor.py,sha256=WlVcfc4kdiCz0Fc1Ybe5GapN2stK0C_0DIymbiGpZfI,3420
11
- lite_agent-0.1.0.dist-info/METADATA,sha256=oFRlVtYwsr1P9RPOP2JNu309-Jpqc95f-TYrExmrFBc,972
12
- lite_agent-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- lite_agent-0.1.0.dist-info/RECORD,,