A simple agent powered by OpenAI that integrates with Linear to provide current weather and time information. The bot is set up to be deployed to a Cloudflare worker.
The bot can look up coordinates for cities, get current weather conditions, and provide local time information for any location. It responds to AgentSession
webhooks from Linear and creates AgentActivity
entries in response to prompts from users in Linear.
The agent has access to three main tools:
getCoordinates(city_name)
- Get coordinates for a citygetWeather(lat, long)
- Get current weather for given coordinates (latitude first, then longitude)getTime(lat, long)
- Get current time for given coordinates (latitude first, then longitude)
- "What tools do you have access to?"
- "What's the weather like in Paris?"
- "What time is it in Tokyo?"
- "Tell me about the weather and time in New York"
The project is built as a Cloudflare Worker with the following structure:
src/
├── index.ts # Main worker entry point
├── lib/
│ ├── agent/
│ │ ├── agentClient.ts # Main agent logic
│ │ ├── tools.ts # Tool implementations
│ │ └── prompt.ts # Prompt provided to LLM
│ └── oauth.ts # Linear OAuth handling
│ └── types.ts # TypeScript type definitions
- Cloudflare account
- Linear workspace with permissions to create an OAuth app
- OpenAI API key
-
Install dependencies
npm install
-
Configure Cloudflare environment
-
Set your
WORKER_URL
andLINEAR_CLIENT_ID
variables inwrangler.jsonc
-
Set the client secret, webhook secret, and OpenAI API key via wrangler
wrangler secret put LINEAR_CLIENT_SECRET wrangler secret put LINEAR_WEBHOOK_SECRET wrangler secret put OPENAI_API_KEY
- Create a KV namespace and set its ID in
wrangler.jsonc
as well
wrangler kv namespace create "WEATHER_BOT_TOKENS"
-
-
Deploy
npm run deploy
- Create a new OAuth app in Linear
- Set the redirect URI to your deployed worker URL +
/oauth/callback
- Enable webhooks, and subscribe to agent session webhooks (and app user notification webhooks, if you'd like)
- Copy the client ID, client secret, and webhook signing secret to use in your Cloudflare worker
# Start local development server
npm run dev
POST /webhook
- Endpoint that receives Linear webhooks forAgentSession
andAgentActivity
creationGET /oauth/authorize
- OAuth authorization endpointGET /oauth/callback
- OAuth callback handler
- Fork the repository
- Create a feature branch
- Make changes as necessary
- Update the tools to different ones based on your use case
- Handle converting the agent's response into a Linear activity based on your custom prompt
- Handle additional webhooks involving your agent
This project is licensed under the MIT License.