|
1 | 1 | # Inspect API |
2 | 2 |
|
3 | | -## Overview |
4 | | -The Inspect API provides "how to use" information for a specific symbol. While the Symbol API focuses on "what it is" (implementation details), the Inspect API is designed to help Agents understand how to correctly call or interact with a symbol by providing its signature, documentation, and real-world usage examples. |
| 3 | +The Inspect API provides detailed information about a specific code symbol, |
| 4 | +including its source code and documentation. It is the primary way for an |
| 5 | +Agent to understand the implementation and usage of a function, class, or variable. |
5 | 6 |
|
6 | | -## When to Use |
7 | | -- **Learning to call an API**: When an Agent needs to know the parameters, types, and return values of a function. |
8 | | -- **Understanding usage patterns**: When an Agent wants to see how other parts of the codebase call a specific method to avoid common mistakes. |
9 | | -- **Contextual documentation**: When the Agent needs a high-level summary of a symbol's purpose without reading the entire implementation. |
| 7 | +## Example Usage |
10 | 8 |
|
11 | | -## Key Differences from Symbol API |
12 | | -| Feature | Inspect API | Symbol API | |
13 | | -|---------|-------------|------------| |
14 | | -| **Primary Focus** | How to use the symbol | What the symbol is/does | |
15 | | -| **Content** | Signature, Docstring, Usage Examples | Full Source Code, Implementation | |
16 | | -| **Goal** | Integration & Calling | Understanding Implementation | |
17 | | -| **Context** | External perspective | Internal perspective | |
| 9 | +### Scenario 1: Getting function documentation and implementation |
18 | 10 |
|
19 | | -## Request Schema |
20 | | -- `locate`: The target symbol to inspect (supports `file_path`, `symbol_path`, `find`, etc.). |
21 | | -- `include_usage`: (Boolean) Whether to include real-world usage examples from the codebase. |
22 | | -- `max_usage_examples`: (Integer) Maximum number of usage examples to return. |
| 11 | +Request: |
23 | 12 |
|
24 | | -## Response Schema |
25 | | -- `symbol`: Basic information about the symbol (name, kind, location). |
26 | | -- `signature`: The formal signature of the symbol (e.g., function parameters and return types). |
27 | | -- `documentation`: The docstring or comments associated with the symbol. |
28 | | -- `usages`: A list of code snippets showing how the symbol is used elsewhere. |
29 | | - |
30 | | -## Example: Inspecting a function |
31 | | -**Request:** |
32 | 13 | ```json |
33 | 14 | { |
34 | 15 | "locate": { |
35 | | - "file_path": "src/utils/auth.py", |
| 16 | + "file_path": "src/main.py", |
36 | 17 | "scope": { |
37 | | - "symbol_path": ["verify_token"] |
| 18 | + "symbol_path": ["calculate_total"] |
38 | 19 | } |
39 | | - }, |
40 | | - "include_usage": true, |
41 | | - "max_usage_examples": 2 |
| 20 | + } |
42 | 21 | } |
43 | 22 | ``` |
44 | 23 |
|
45 | | -**Response:** |
| 24 | +### Scenario 2: Getting class information |
| 25 | + |
| 26 | +Request: |
| 27 | + |
46 | 28 | ```json |
47 | 29 | { |
48 | | - "symbol": { |
49 | | - "name": "verify_token", |
50 | | - "kind": "function", |
51 | | - "location": { "uri": "file:///src/utils/auth.py", "range": { ... } } |
52 | | - }, |
53 | | - "signature": "def verify_token(token: str, secret: str = None) -> UserPayload", |
54 | | - "documentation": "Verifies a JWT token and returns the decoded payload.\n\n:param token: The JWT string to verify.\n:param secret: Optional secret override.", |
55 | | - "usages": [ |
56 | | - { |
57 | | - "file_path": "src/api/middleware.py", |
58 | | - "line": 42, |
59 | | - "code": "payload = verify_token(auth_header.split(' ')[1])" |
| 30 | + "locate": { |
| 31 | + "file_path": "src/models.py", |
| 32 | + "scope": { |
| 33 | + "symbol_path": ["User"] |
60 | 34 | } |
61 | | - ] |
| 35 | + } |
62 | 36 | } |
63 | 37 | ``` |
64 | 38 |
|
65 | | -**Markdown Output:** |
66 | | -```markdown |
67 | | -# Inspect: `verify_token` |
68 | | - |
69 | | -**Signature:** `def verify_token(token: str, secret: str = None) -> UserPayload` |
70 | | - |
71 | | ---- |
72 | | - |
73 | | -Verifies a JWT token and returns the decoded payload. |
74 | | - |
75 | | -:param token: The JWT string to verify. |
76 | | -:param secret: Optional secret override. |
77 | | - |
78 | | -## Usage Examples |
79 | | - |
80 | | -### src/api/middleware.py:42 |
81 | | -```python |
82 | | -41 | auth_header = request.headers.get('Authorization') |
83 | | -42 | payload = verify_token(auth_header.split(' ')[1]) |
84 | | -43 | request.user = payload |
85 | | -``` |
| 39 | +## References |
86 | 40 |
|
87 | | -## See Also |
88 | | -- [Symbol API](./symbol.md) |
89 | | -- [Reference API](./reference.md) |
| 41 | +- [InspectRequest.json](./InspectRequest.json) |
| 42 | +- [InspectResponse.json](./InspectResponse.json) |
0 commit comments