Coverage for src/lite_agent/types/events.py: 100%

46 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2025-08-25 22:58 +0900

1from typing import Literal 

2 

3from litellm.types.utils import ModelResponseStream 

4from pydantic import BaseModel 

5 

6from .messages import NewAssistantMessage 

7 

8 

9class Usage(BaseModel): 

10 input_tokens: int 

11 output_tokens: int 

12 

13 

14class Timing(BaseModel): 

15 latency_ms: int 

16 output_time_ms: int 

17 

18 

19class CompletionRawEvent(BaseModel): 

20 """ 

21 Define the type of chunk 

22 """ 

23 

24 type: Literal["completion_raw"] = "completion_raw" 

25 raw: ModelResponseStream 

26 

27 

28class ResponseRawEvent(BaseModel): 

29 """ 

30 Define the type of response raw chunk 

31 """ 

32 

33 type: Literal["response_raw"] = "response_raw" 

34 raw: object 

35 

36 

37class UsageEvent(BaseModel): 

38 """ 

39 Define the type of usage info chunk 

40 """ 

41 

42 type: Literal["usage"] = "usage" 

43 usage: Usage 

44 

45 

46class TimingEvent(BaseModel): 

47 """ 

48 Define the type of timing info chunk 

49 """ 

50 

51 type: Literal["timing"] = "timing" 

52 timing: Timing 

53 

54 

55class AssistantMessageEvent(BaseModel): 

56 """ 

57 Define the type of assistant message chunk 

58 """ 

59 

60 type: Literal["assistant_message"] = "assistant_message" 

61 message: NewAssistantMessage 

62 

63 

64class FunctionCallEvent(BaseModel): 

65 """ 

66 Define the type of tool call chunk 

67 """ 

68 

69 type: Literal["function_call"] = "function_call" 

70 call_id: str 

71 name: str 

72 arguments: str 

73 

74 

75class FunctionCallOutputEvent(BaseModel): 

76 """ 

77 Define the type of tool call result chunk 

78 """ 

79 

80 type: Literal["function_call_output"] = "function_call_output" 

81 tool_call_id: str 

82 name: str 

83 content: str 

84 execution_time_ms: int | None = None 

85 

86 

87class ContentDeltaEvent(BaseModel): 

88 """ 

89 Define the type of message chunk 

90 """ 

91 

92 type: Literal["content_delta"] = "content_delta" 

93 delta: str 

94 

95 

96class FunctionCallDeltaEvent(BaseModel): 

97 """ 

98 Define the type of tool call delta chunk 

99 """ 

100 

101 type: Literal["function_call_delta"] = "function_call_delta" 

102 tool_call_id: str 

103 name: str 

104 arguments_delta: str 

105 

106 

107AgentChunk = CompletionRawEvent | ResponseRawEvent | UsageEvent | TimingEvent | FunctionCallEvent | FunctionCallOutputEvent | ContentDeltaEvent | FunctionCallDeltaEvent | AssistantMessageEvent 

108 

109AgentChunkType = Literal[ 

110 "completion_raw", 

111 "response_raw", 

112 "usage", 

113 "timing", 

114 "function_call", 

115 "function_call_output", 

116 "content_delta", 

117 "function_call_delta", 

118 "assistant_message", 

119]