How to Build an Advanced Agentic AI System with Planning, Tool Calling, Memory, and Self-Critique Using OpenAI API
TOOLS = { “calc”: lambda expression: _safe_calc(expression), “kb_search”: lambda query, k=3: _kb_search(query, int(k)), “extract_json”: lambda text: _extract_json(text), “write_file”: lambda path, content: _write_file(path, content), } TOOL_SCHEMAS = [ {“type”: “function”,”function”:{“name”:”calc”,”description”:”Safely compute a numeric expression.”,”parameters”:{“type”:”object”,”properties”:{“expression”:{“type”:”string”}},”required”:[“expression”]}}}, {“type”: “function”,”function”:{“name”:”kb_search”,”description”:”Search internal mini knowledge base.”,”parameters”:{“type”:”object”,”properties”:{“query”:{“type”:”string”},”k”:{“type”:”integer”,”default”:3}},”required”:[“query”]}}}, {“type”: “function”,”function”:{“name”:”extract_json”,”description”:”Extract and parse first JSON object from text.”,”parameters”:{“type”:”object”,”properties”:{“text”:{“type”:”string”}},”required”:[“text”]}}}, {“type”: “function”,”function”:{“name”:”write_file”,”description”:”Write content to a file path.”,”parameters”:{“type”:”object”,”properties”:{“path”:{“type”:”string”},”content”:{“type”:”string”}},”required”:[“path”,”content”]}}},…
