Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
py 66 lines 2.06 KB
Raw
1 """
2 Logs module for the Composio SDK.
3
4 Exposes ``composio.logs`` for searching and retrieving tool execution logs.
5 """
6
7 from __future__ import annotations
8
9 import typing_extensions as te
10
11 from composio.client.types import (
12 log_create_tool_execution_params,
13 log_create_tool_execution_response,
14 log_retrieve_tool_execution_response,
15 )
16 from composio.core.models.base import Resource
17
18
19 class Logs(Resource):
20 """Search and retrieve tool execution logs."""
21
22 def search(
23 self,
24 **params: te.Unpack[
25 log_create_tool_execution_params.LogCreateToolExecutionParams
26 ],
27 ) -> log_create_tool_execution_response.LogCreateToolExecutionResponse:
28 """
29 Search tool execution logs with filters, pagination, and a time range.
30
31 Despite the underlying ``POST`` verb this is a read-only search.
32
33 :param limit: Maximum number of logs to return.
34 :param cursor: Pagination cursor from a previous response.
35 :param filters: Filter clauses to narrow the search.
36 :param time_range: Time window to search within.
37 :return: Matching logs plus a ``next_cursor`` for pagination. A charged
38 tool log has an exact USD string at
39 ``log.metadata.instant_charge``.
40
41 Example:
42 page = composio.logs.search(
43 limit=20,
44 filters=[
45 {"field": "toolkit_slug", "operator": "==", "value": "github"}
46 ],
47 )
48 for log in page.logs:
49 print(log.id)
50 """
51 return self._client.logs.create_tool_execution(**params)
52
53 def get(
54 self, id: str
55 ) -> log_retrieve_tool_execution_response.LogRetrieveToolExecutionResponse:
56 """
57 Retrieve a single tool execution log by id.
58
59 :param id: The log id.
60 :return: The full log entry. For charged calls,
61 ``log.metadata.instant_charge`` is the exact USD amount.
62
63 Example:
64 log = composio.logs.get("log_123")
65 """
66 return self._client.logs.retrieve_tool_execution(id)