Building Custom AI Agents Just Got EASIER ![rw-book-cover](https://i.ytimg.com/vi/NsROagHaKxA/maxresdefault.jpg) ## Metadata - Author: [[Better Stack]] - Full Title: Building Custom AI Agents Just Got EASIER - Category: #articles - Document Note: --- tags: [ai-agents, claude-code, sdk] author: an unnamed author source: [YouTube] reference: [https://www.youtube.com/watch?v=NsROagHaKxA] date created: {{date:YYYY-MM-DD}} {{time:HH:mm}} --- # 🏷️ Title: Building Custom AI Agents Just Got EASIER ## 🧭 Table of Contents - [📝 Summary](#-summary) - [📖 Main Content](#-main-content) - [🗒️ Notes](#️-notes) - [📚 References](#-references) - [🗣️ Paraphrase](#️-paraphrase) - [📰 Newsletter](#-newsletter) - [✅ Action Items](#-action-items) - [🧪 Hypotheses](#-hypotheses) - [📊 Methodology](#-methodology) - [❓ Questions](#-questions) - [🔮 Future Research](#-future-research) - [💡 Implications](#-implications) - [🧠 Learning Styles Assessment](#-learning-styles-assessment) - [📊 Accessibility Assessment](#-accessibility-assessment) - [🌍 DEIB Assessment](#-deib-assessment) - [✅ Logical Validity](#-logical-validity) - [🛡️ DARVO Analysis](#-darvo-analysis) - [🎯 Conclusion](#-conclusion) ### 🔗 References - Include links cited in or relevant to the article. ## 📝 Summary - The video shows building a custom agent using the Claude Code SDK. - It highlights streaming input, custom tools, hooks, and prompt control. :contentReference[oaicite:0]{index=0} - Stakeholders include OSS developers, OSPOs, and WordPress plugin authors. - Risks include brittle prompts, unclear tool scopes, and maintenance overhead. :contentReference[oaicite:1]{index=1} - Bottom line: the SDK supports production agent patterns with clear docs. :contentReference[oaicite:2]{index=2} ## 📖 Main Content - The SDK supports single prompts and streaming input. Anthropic recommends streaming input for agents. :contentReference[oaicite:3]{index=3} - Hooks let you intercept events, extend behavior, and add guardrails. :contentReference[oaicite:4]{index=4} - You can fully control system prompts or layer output styles. Capabilities differ. :contentReference[oaicite:5]{index=5} - The SDK integrates with MCP. You can expose internal tools as MCP servers. :contentReference[oaicite:6]{index=6} - Custom tools use `createSdkMcpServer` and `tool` to define typed inputs and actions. :contentReference[oaicite:7]{index=7} - Session management, subagents, slash commands, todos, and cost tracking are built-in. :contentReference[oaicite:8]{index=8} - This aligns with developer workflows for IDE-like agents and internal bots. :contentReference[oaicite:9]{index=9} - Uncertainties remain around feature stability and model differences over time. :contentReference[oaicite:10]{index=10} ### 🗒️ Notes #### ⏱️ [00:04](https://www.youtube.com/watch?v=NsROagHaKxA&t=4) SDK value and context - Custom tools and hooks simplify agent building. - Knowing agent basics matters as adoption grows. #### ⏱️ [00:59](https://www.youtube.com/watch?v=NsROagHaKxA&t=59) Single-prompt demo - TypeScript example returns model info and session metadata. - Options can set the specific model. #### ⏱️ [01:47](https://www.youtube.com/watch?v=NsROagHaKxA&t=107) Streaming input mode - Generator yields message objects with IDs and roles. - Tools run to count files and compute results. :contentReference[oaicite:11]{index=11} #### ⏱️ [02:38](https://www.youtube.com/watch?v=NsROagHaKxA&t=158) Interactive loop - CLI accepts follow-up prompts. - Tool calls print for transparency. #### ⏱️ [03:27](https://www.youtube.com/watch?v=NsROagHaKxA&t=207) System prompt control - Overwriting prompts changes behavior and tool usage. :contentReference[oaicite:12]{index=12} - Output styles and appended prompts differ in control. :contentReference[oaicite:13]{index=13} #### ⏱️ [04:20](https://www.youtube.com/watch?v=NsROagHaKxA&t=260) Focused agents - Custom prompts can restrict tools. :contentReference[oaicite:14]{index=14} - Use cases include tutoring or internal controls. #### ⏱️ [05:12](https://www.youtube.com/watch?v=NsROagHaKxA&t=312) Custom tools via MCP - Define a pricing tool using `createSdkMcpServer` and `tool`. :contentReference[oaicite:15]{index=15} - Zod validates input; the tool returns totals. #### ⏱️ [06:08](https://www.youtube.com/watch?v=NsROagHaKxA&t=368) Feature survey - Permissions, todos, slash commands, subagents, sessions, and hooks exist. :contentReference[oaicite:16]{index=16} - The SDK centralizes agent patterns. ## 📚 References - [Video: Building Custom AI Agents Just Got EASIER](https://www.youtube.com/watch?v=NsROagHaKxA) - [Claude Code overview](https://docs.claude.com/en/claude-code/overview) :contentReference[oaicite:17]{index=17} - [Streaming Input](https://docs.claude.com/en/api/agent-sdk/streaming-input) :contentReference[oaicite:18]{index=18} - [Hooks](https://docs.claude.com/en/api/agent-sdk/hooks) :contentReference[oaicite:19]{index=19} - [Modifying system prompts](https://docs.claude.com/en/api/agent-sdk/system-prompts) :contentReference[oaicite:20]{index=20} - [MCP in the SDK](https://docs.claude.com/en/api/agent-sdk/mcp) :contentReference[oaicite:21]{index=21} - [Custom Tools](https://docs.claude.com/en/api/agent-sdk/custom-tools) :contentReference[oaicite:22]{index=22} - [Subagents](https://docs.claude.com/en/api/agent-sdk/subagents) :contentReference[oaicite:23]{index=23} - [Session Management](https://docs.claude.com/en/api/agent-sdk/session-management) :contentReference[oaicite:24]{index=24} - [Slash Commands](https://docs.claude.com/en/api/agent-sdk/slash-commands) :contentReference[oaicite:25]{index=25} - [Todo Lists](https://docs.claude.com/en/api/agent-sdk/todo-tracking) :contentReference[oaicite:26]{index=26} - [Cost and Usage](https://docs.claude.com/en/api/agent-sdk/cost-tracking) :contentReference[oaicite:27]{index=27} ## 🗣️ Paraphrase - The SDK now supports richer, controllable agents through streaming, hooks, and custom tools. - You can tailor prompts, expose internal functions via MCP, and manage sessions for iterative work. ## 📰 Newsletter - Building WordPress-focused agents just got friendlier. Claude Code’s SDK supports custom tools, hooks, and sessions. :contentReference[oaicite:28]{index=28} - Imagine agents triaging plugin issues, generating block code, or drafting Docs with policies applied. - Start here: Claude Code docs, MCP guide, and system-prompt strategies. :contentReference[oaicite:29]{index=29} - Pair this with WordPress Developer Resources and WordPress Playground for rapid testing. - Keep funding transparent with The WPCC updates and FAIR.pm governance artifacts. ## ✅ Action Items - **DevRel** - Publish a “WP Agent Starter” repo with SDK templates. - Record a demo on streaming input and MCP tools. :contentReference[oaicite:30]{index=30} - Measure success by repo stars, PRs, and tutorial completions. - **Developer advocacy: plans, talks, demos, and measurable outcomes.** - Propose WordCamp talk: “Agents for Plugin Teams.” - Track activation by sample project forks and usage telemetry. - **Education: workshops, curricula, office hours, mentorship programs.** - Create a 3-session course: prompts, tools, and governance. :contentReference[oaicite:31]{index=31} - **Developer experience: docs, SDKs, examples, templates, quickstarts.** - Ship CLI scaffolds for WordPress agent tasks and slash commands. :contentReference[oaicite:32]{index=32} - **Developer marketing: campaigns, content, funnels, and attribution.** - Run a “7-day agent sprint” with clear CTAs and UTM tracking. - **Community management: moderation, code of conduct ops, surveys.** - Add agent usage norms to community guidelines. - **Internal/external/cross-project: align goals, SLAs, and feedback loops.** - Define SLAs for agent uptime and tool latency. - **OSPO** - **Policy & Governance:** Draft a contributor agent policy and escalation paths. - **License Compliance:** Scan custom tools for license risks weekly. - **Security Management:** Establish vuln intake for agent tools and sessions. - **Software Inventory:** Maintain an SBOM for agent tools and prompts. - **Developer Support:** Hold MCP office hours and code reviews. :contentReference[oaicite:33]{index=33} - **Community Engagement:** Fund upstream tool maintainers via microgrants. - * - Summary: Build your first AI agent with the Claude Code SDK in less than 100 lines of code. This video tutorial teaches you how to create custom agents with custom tools, system prompts, and MCP servers for complete AI behavior control. Learn to implement streaming input mode JavaScript generators and build interactive agents that handle real tasks. Perfect for developers exploring AI agent development. 🔗 Relevant Links Claude Code SDK docs: https://docs.claude.com/en/docs/claude-code/sdk/sdk-overview ❤️ More about us Radically better observability stack: https://betterstack.com/ Written tutorials: https://betterstack.com/community/ Example projects: https://github.com/BetterStackHQ 📱 Socials Twitter: https://twitter.com/betterstackhq Instagram: https://www.instagram.com/betterstackhq/ TikTok: https://www.tiktok.com/@betterstack LinkedIn: https://www.linkedin.com/company/betterstack - URL: https://www.youtube.com/watch?v=NsROagHaKxA The Claude Code team have recently announced custom tool support and hooks to Claude Code SDK, making it one step easier for you to create your own custom agent for your specific needs. And with some companies now hiring AI agents instead of actual humans, it's more important than ever to know how to build a basic agent. But what makes custom tools and hooks so important? and how do I even get started building an agent with the Claude Code SDK? I'll answer all these questions. And before we get started, make sure you hit that subscribe button. So, this is a really basic example of using the Claude Code SDK. As you can see, we're importing the same library that we would if we were using the Claude Code CLI, which is really cool. From here, we're taking the query function and below it, we're passing in the argument of prompt, which is what model is this? And then from there we're console logging the result. This if statement here is used to make sure that we don't get any type errors from TypeScript. So if we run this file we just get the name of the model that's being used. We could add a specific model in options like claude haiku. And that is the model that will be used for future prompts. And if we wanted to see the full message, we could get rid of results. And we can see all the information we get back from the actual result to the session ID, the token usage, cost, and much more. This is pretty awesome because we get access to all of clawed code hooks and tools, which I'll show you later. But right now, this basic example is only useful for a single prompt. If we wanted to have something more complicated, we'd have to use a different approach known as streaming input mode, which is the mode recommended by Anthropic. To do that, we'd have to create a generator function that yields an object with the type message and a bunch of other things to keep Typescript happy, like the parent tool use ID, the session ID, and setting type and ro to as const. We need to yield one of these objects each time we want to send a prompt to the model. So, this has two prompts. The first one is to ask how many files are in this project, then to multiply that number by five. And if we run this script, we just get the result because that's the only thing we're printing. But there are actually a lot of things taking place like using tools to count the number of files. So if we update the code to print out everything is doing, we can see we get a lot more information including possible tool calls and then the actual result. So let's expose this information, but also let's make it so that I, the user, can continue talking to the model after it's given me a result. And now we've updated the code to do that. So first we're getting the user input which is just using the standard in. Then once we have an input, we'll pass that value into the content which will be the prompt. From there the agent will return the result and then ask the human for a follow-up prompt. If the agent uses any tools, we'll also print that out as well so we can see the exact tool that's been used. So if we run the script, we get this box with a welcome message and the option for the human to add a prompt. Note the box and the colors were done with this code. Let's give it a prompt like how many files are in this project excluding the node modules directory. And we can see it's used the bash tool then the glob tool before giving us a response and asking us to prompt again. This is actually very impressive. I mean we've built the beginnings of claude code itself and we've only used one function from the SDK with a single file that has 91 lines of code. But we can make this even better. The beauty of creating a custom agent is that you can overwrite the system prompt, making it completely different from the default clawed code. Looking at the Claude SDK documentation, there are several ways you can change the system prompt from using output styles to append system prompt to custom system prompt. And this option is the only one that gives you complete control over the system prompt. Output styles gives you more features, but this option, in my opinion, allows you to truly create your own agent. Let me give you an example. Here we have a custom prompt that tells Claude to always respond with, "I don't know." And then respond with even angrier responses the more prompts the user gives it. So, we can ask, "What model is this?" And Claude responds with, "I don't know." But what's even interesting is that if we ask it how many files are in this project, it also responds with, "I don't know." but it doesn't even attempt to make any tool calls. This is because the default system prompt includes tool usage instructions and available tools. So, our custom system prompt has limited the amount of tools that Claude will use. This is really cool because you could create a custom agent for absolutely anything. An agent specific to your kids maths homework that doesn't give them the answer but teaches them instead or an internal company agent with limited abilities. Let's go through one more awesome feature of the claude code SDK which is custom tools. For this I'm using the create SDK MCP server function which has a name version and also uses the tool function from the same claude code SDK. And here we're creating a single tool for our MCP server which takes in an input using ZOD of size drink type extras and currency. Then there are prices associated with the size and the extras. And then it calculates the total price of the drink based on the user prompt which the model figures out from the tool description. Then in the index.ts file, I import the exported custom server and add it to the allowed tools in this format. I've also appended it to the system prompt so that Claude gives me a short answer. So if we wanted the price of a medium oat milk latte, then that should be 4.6. And if we ask the model, it first uses our MCP tool before giving us a result of $4.60. Now, this may seem like a trivial example, but imagine that this is data from a database in a tool that you use or an internal function specific to your app. Now, I could go on and on adding more things to our project because the Claude Code SDK has so many features from handling permissions, showing a to-do list of tasks the agent is going to complete using slash commands, sub aents, session management so you can return to previous conversations, and even specifying custom hooks. Although, if you already have global clause code hooks, output styles, or sub agents, your custom agent has access to those, too. But I think this is a good place to stop. What are your thoughts on the SDK? Is it something you think you'll use or will you just stick with the regular clawed code? Let me know in the comments. And until next time, happy coding., Building Custom AI Agents Just Got EASIER, Better Stack, 01k6ef1szmewrwqcfsj7wbn2p3.