Skip to content

Commit 3d9f222

Browse files
Add comprehensive scope keys documentation
- Created detailed explanation of how scope keys work across platforms - Added examples for Slack, Linear, GitHub, and API interactions - Explained why scope keys matter for context inheritance - Included best practices and troubleshooting guide - Updated docs navigation to include new architecture section
1 parent 678912f commit 3d9f222

2 files changed

Lines changed: 259 additions & 81 deletions

File tree

docs/architecture/scope-keys.mdx

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: "Scope Keys: How Context Inheritance Works"
3+
description: "Understanding how Codegen groups related interactions and inherits context across conversations"
4+
---
5+
6+
# Scope Keys: How Context Inheritance Works
7+
8+
Scope keys are Codegen's way of grouping related agent runs together so that context can be inherited between interactions. Think of them as conversation threads that help Codegen understand when different requests are part of the same ongoing work.
9+
10+
## What Are Scope Keys?
11+
12+
A scope key is a unique identifier that groups related agent interactions. When you interact with Codegen multiple times in the same "scope," each new interaction can build on the context and work from previous interactions in that scope.
13+
14+
This enables powerful workflows like:
15+
- Continuing conversations in the same Slack thread
16+
- Building on previous work in the same Linear ticket
17+
- Adding commits to existing PRs instead of creating new ones
18+
- Maintaining context across multiple requests
19+
20+
## How Scope Keys Work by Platform
21+
22+
### Slack Threads
23+
**Scope Key Format:** `slack-{thread_timestamp}`
24+
25+
When you mention Codegen in a Slack thread, all messages in that thread share the same scope key. This means:
26+
- Codegen remembers the entire conversation history
27+
- Follow-up requests build on previous work
28+
- Context from earlier messages is automatically inherited
29+
30+
```
31+
Thread: "Can you fix the login bug?"
32+
├── Codegen creates PR #123
33+
└── "Please also add input validation"
34+
└── Codegen adds commits to PR #123 (same scope!)
35+
```
36+
37+
### Linear Issues
38+
**Scope Key Format:** `linear-{issue_id}`
39+
40+
All work on the same Linear issue shares a scope key. This enables:
41+
- Building on previous implementations
42+
- Maintaining context across multiple comments
43+
- Continuing work where you left off
44+
45+
```
46+
Linear Issue CG-456: "Improve test coverage"
47+
├── Comment: "Add tests for auth module"
48+
│ └── Codegen creates PR #789
49+
└── Comment: "Also need integration tests"
50+
└── Codegen adds to PR #789 (same scope!)
51+
```
52+
53+
### GitHub PRs
54+
**Scope Key Format:** `github-pr-{pr_number}-{repo_id}`
55+
56+
Work on the same PR is grouped together, allowing:
57+
- Adding commits to existing PRs
58+
- Responding to review feedback
59+
- Iterating on the same feature branch
60+
61+
```
62+
PR #123: "Add user authentication"
63+
├── Initial PR created
64+
├── Review comment: "Fix the validation logic"
65+
│ └── Codegen adds fixing commit
66+
└── Review comment: "Add error handling"
67+
└── Codegen adds another commit (same PR!)
68+
```
69+
70+
### API Calls
71+
**Scope Key Format:** `api-{run_id}` or derived from task timeline
72+
73+
API interactions can inherit scope from:
74+
- The task timeline if provided
75+
- Previous API calls in the same session
76+
- Falls back to unique run ID if no context
77+
78+
## Why This Matters
79+
80+
### ✅ With Scope Keys (Good)
81+
```
82+
Slack Thread:
83+
You: "Create a PR to fix the login bug"
84+
Codegen: Creates PR #123
85+
86+
You: "Please also add input validation"
87+
Codegen: Adds commits to PR #123 ← Same PR!
88+
89+
You: "The tests are failing"
90+
Codegen: Fixes tests in PR #123 ← Still same PR!
91+
```
92+
93+
### ❌ Without Scope Keys (Bad)
94+
```
95+
You: "Create a PR to fix the login bug"
96+
Codegen: Creates PR #123
97+
98+
You: "Please also add input validation"
99+
Codegen: Creates PR #124 ← New PR! 😞
100+
101+
You: "The tests are failing"
102+
Codegen: Creates PR #125 ← Another new PR! 😞
103+
```
104+
105+
## Best Practices
106+
107+
### Do This ✅
108+
- **Continue conversations in the same thread/ticket** - This ensures context is inherited
109+
- **Ask for changes in the same scope** - Codegen will update existing work
110+
- **Reference previous work** - Codegen can build on what it already knows
111+
112+
### Avoid This ❌
113+
- **Starting new threads for related work** - Context gets lost
114+
- **Creating new tickets for follow-ups** - Breaks the scope chain
115+
- **Asking for "new PRs" unnecessarily** - Usually you want to update existing work
116+
117+
## Technical Implementation
118+
119+
Scope keys are implemented in the agent runner system:
120+
121+
```python
122+
# Each platform implements scope key generation
123+
class SlackRunner:
124+
def agent_run_scope_key(self) -> str:
125+
return f"slack-{self.slack_thread_ts}"
126+
127+
class LinearRunner:
128+
def agent_run_scope_key(self) -> str:
129+
return f"linear-{self.linear_issue_id}"
130+
131+
class GithubRunner:
132+
def agent_run_scope_key(self) -> str:
133+
return f"github-pr-{self.pr_number}-{self.repo_id}"
134+
```
135+
136+
When a new agent run starts, the system:
137+
1. Generates the appropriate scope key
138+
2. Looks up previous runs with the same scope key
139+
3. Inherits context from those previous runs
140+
4. Continues the work in the same "conversation"
141+
142+
## Troubleshooting
143+
144+
**Problem:** Codegen keeps creating new PRs instead of updating existing ones
145+
**Solution:** Make sure you're asking for changes in the same Slack thread, Linear issue, or PR where the original work was done.
146+
147+
**Problem:** Codegen doesn't remember previous context
148+
**Solution:** Check that you're interacting in the same scope (same thread/ticket/PR) as the previous interaction.
149+
150+
**Problem:** Context seems to be inherited from unrelated work
151+
**Solution:** This might indicate a scope key collision - check that you're working in the right thread/ticket/PR.
152+
153+
---
154+
155+
Understanding scope keys helps you work more effectively with Codegen by ensuring your requests build on each other rather than starting from scratch each time.
156+

docs/docs.json

Lines changed: 103 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,88 +8,110 @@
88
"dark": "#a277ff"
99
},
1010
"favicon": "/favicon.svg",
11-
"navigation": {
12-
"tabs": [
13-
{
14-
"tab": "Documentation",
15-
"groups": [
16-
{
17-
"group": "Overview",
18-
"pages": [
19-
"introduction/overview",
20-
"introduction/api",
21-
"introduction/prompting",
22-
"introduction/community",
23-
"introduction/about",
24-
"introduction/faq"
25-
]
26-
},
27-
{
28-
"group": "Capabilities",
29-
"pages": ["capabilities/capabilities", "capabilities/wake-up"]
30-
},
31-
{
32-
"group": "Integrations",
33-
"pages": [
34-
"integrations/github",
35-
"integrations/slack",
36-
"integrations/linear",
37-
"integrations/notion",
38-
"integrations/figma",
39-
"integrations/circleci",
40-
"integrations/web-search",
41-
"integrations/postgres"
42-
]
43-
},
44-
{
45-
"group": "Sandboxes",
46-
"pages": [
47-
"sandboxes/overview",
48-
"sandboxes/setup-commands",
49-
"sandboxes/environment-variables",
50-
"sandboxes/secrets",
51-
"sandboxes/editor",
52-
"sandboxes/web-preview"
53-
]
54-
},
55-
{
56-
"group": "Settings",
57-
"pages": ["settings/repo-rules", "settings/model-configuration"]
58-
}
59-
]
60-
},
61-
{
62-
"tab": "API Reference",
63-
"groups": [
64-
{
65-
"group": "Endpoints",
66-
"openapi": {
67-
"source": "/api-reference/openapi3.json",
68-
"directory": "api-reference"
69-
}
70-
}
71-
]
72-
},
73-
{
74-
"tab": "Blog",
75-
"groups": [
76-
{
77-
"group": "Blog",
78-
"pages": ["blog/posts", "blog/devin", "blog/act-via-code"]
79-
}
80-
]
81-
},
82-
{
83-
"tab": "Changelog",
84-
"groups": [
85-
{
86-
"group": "Changelog",
87-
"pages": ["changelog/changelog"]
11+
"navigation": [
12+
{
13+
"group": "Get Started",
14+
"pages": [
15+
"introduction",
16+
"quickstart",
17+
"development"
18+
]
19+
},
20+
{
21+
"group": "Essentials",
22+
"pages": [
23+
"essentials/markdown",
24+
"essentials/code",
25+
"essentials/images",
26+
"essentials/settings",
27+
"essentials/navigation"
28+
]
29+
},
30+
{
31+
"group": "Architecture",
32+
"pages": [
33+
"architecture/scope-keys"
34+
]
35+
},
36+
{
37+
"tab": "Documentation",
38+
"groups": [
39+
{
40+
"group": "Overview",
41+
"pages": [
42+
"introduction/overview",
43+
"introduction/api",
44+
"introduction/prompting",
45+
"introduction/community",
46+
"introduction/about",
47+
"introduction/faq"
48+
]
49+
},
50+
{
51+
"group": "Capabilities",
52+
"pages": ["capabilities/capabilities", "capabilities/wake-up"]
53+
},
54+
{
55+
"group": "Integrations",
56+
"pages": [
57+
"integrations/github",
58+
"integrations/slack",
59+
"integrations/linear",
60+
"integrations/notion",
61+
"integrations/figma",
62+
"integrations/circleci",
63+
"integrations/web-search",
64+
"integrations/postgres"
65+
]
66+
},
67+
{
68+
"group": "Sandboxes",
69+
"pages": [
70+
"sandboxes/overview",
71+
"sandboxes/setup-commands",
72+
"sandboxes/environment-variables",
73+
"sandboxes/secrets",
74+
"sandboxes/editor",
75+
"sandboxes/web-preview"
76+
]
77+
},
78+
{
79+
"group": "Settings",
80+
"pages": ["settings/repo-rules", "settings/model-configuration"]
81+
}
82+
]
83+
},
84+
{
85+
"tab": "API Reference",
86+
"groups": [
87+
{
88+
"group": "Endpoints",
89+
"openapi": {
90+
"source": "/api-reference/openapi3.json",
91+
"directory": "api-reference"
8892
}
89-
]
90-
}
91-
]
92-
},
93+
}
94+
]
95+
},
96+
{
97+
"tab": "Blog",
98+
"groups": [
99+
{
100+
"group": "Blog",
101+
"pages": ["blog/posts", "blog/devin", "blog/act-via-code"]
102+
}
103+
]
104+
},
105+
{
106+
"tab": "Changelog",
107+
"groups": [
108+
{
109+
"group": "Changelog",
110+
"pages": ["changelog/changelog"]
111+
}
112+
]
113+
}
114+
],
93115
"logo": {
94116
"light": "https://cdn.prod.website-files.com/67070304751b9b01bf6a161c/679bcf45bf55446746125835_Codegen_Logomark_Light.svg",
95117
"dark": "https://cdn.prod.website-files.com/67070304751b9b01bf6a161c/679bcf45a3e32761c42b324b_Codegen_Logomark_Dark.svg"

0 commit comments

Comments
 (0)