惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
月光博客
月光博客
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
IT之家
IT之家
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
爱范儿
爱范儿

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Pythonic AI: Mastering the apcore-python SDK
tercel · 2026-06-03 · via DEV Community

Python is the undisputed language of the AI era. It’s the language of research, the language of LLM orchestration (LangChain, CrewAI), and for many, the language of the enterprise backend.

When we designed the apcore-python SDK, our goal was simple: High Perceptibility, Low Intrusion. We wanted to give Python developers a way to make their code "AI-ready" without forcing them to rewrite their entire architecture.

In this nineteenth article of our series, we move from the engine room to the keyboard, showing you how to master the Python SDK to build professional, AI-Perceivable modules.


Defining Modules: The Two Styles

Every developer has a different preference. Some love the structure of classes; others prefer the simplicity of decorators. apcore supports both.

1. The Decorator Style (Fast & Functional)

If you have an existing utility function and you want to turn it into an AI "Skill" in 30 seconds, use the @module decorator.

from apcore import module

@module(id="text.summarize", description="Summarize text for Agentic planning.")
def summarize(text: str, length: int = 100) -> dict:
    # Your logic here...
    return {"summary": "..."}

2. The Class Style (Structured & Extensible)

For modules that require complex state, custom initialization, or detailed behavioral annotations, the class-based approach is superior.

from apcore import Module, ModuleAnnotations, Context
from pydantic import BaseModel

class SendEmailInput(BaseModel):
    to: str
    body: str

class SendEmailModule(Module):
    input_schema = SendEmailInput
    description = "Send secure internal emails."
    annotations = ModuleAnnotations(destructive=False, requires_approval=True)

    def execute(self, inputs: dict, context: Context) -> dict:
        # Business logic...
        return {"status": "sent"}


Pydantic Integration: The Secret Weapon

The "Killer Feature" of apcore-python is its deep integration with Pydantic V2.

In the AI world, your schema's description fields are just as important as the types. apcore-python extracts these descriptions directly from your Pydantic models.

class SearchInput(BaseModel):
    query: str = Field(..., description="The search term. Use keywords, not sentences.")
    limit: int = Field(5, description="Max results to return.")

When you register this module, apcore automatically generates a JSON Schema Draft 2020-12 that includes these descriptions. This ensures that the AI Agent knows exactly how to use each parameter.


Initializing the Core

Starting with v0.18.0, we’ve simplified the APCore constructor to focus on a unified configuration model. You no longer pass multiple paths to the constructor; instead, you load a Config object.

from apcore import APCore, Config

# Load config from apcore.yaml and initialize
config = Config.load("apcore.yaml")
app = APCore(config=config)

This ensures that your security policies, pipeline steps, and registry settings are always in sync across your entire application.


Execution & Async Support

AI Agents are often used in asynchronous environments (web servers, background tasks). The apcore-python SDK is built for this. You can call modules synchronously or asynchronously with full trace propagation.

executor = Executor(registry)

# Async execution with identity propagation
result = await executor.call_async(
    "text.summarize", 
    inputs={"text": "..."}, 
    context=context
)


Conclusion: Built for Developers, Ready for AI

apcore-python isn't just a library; it’s a design pattern. It allows you to build software that is idiomatic for Python developers and perfectly perceivable by AI Agents. By combining the power of Pydantic with the rigor of the apcore protocol, you are building the foundation for a reliable Agentic workforce.

Now that we’ve mastered Python, it’s time to look at the other side of the stack. In our next article, we dive into Type-Safe Agents: Leveraging apcore-js in TypeScript.


This is Article #19 of the **Building the AI-Perceivable World* series. Idiomatic code is the bridge to better AI.*

GitHub: aiperceivable/apcore-python