|
1 | 1 | # Copyright (c) 2025 |
2 | 2 | # Licensed under the Apache License, Version 2.0 |
3 | 3 |
|
4 | | -"""LangChain AFM Interpreter. |
5 | | -
|
6 | | -A Python implementation of the AFM (Agent-Flavored Markdown) specification v0.3.0. |
7 | | -
|
8 | | -This package provides: |
9 | | -
|
10 | | -- **Parser**: Parse AFM files into structured Python objects |
11 | | -- **Agent**: Execute agents using LangChain |
12 | | -- **Interfaces**: Console chat, web chat, and webhook handlers |
13 | | -
|
14 | | -Example usage:: |
15 | | -
|
16 | | - from afm_cli import parse_afm_file, Agent |
17 | | - from afm_cli.interfaces import run_console_chat |
18 | | -
|
19 | | - afm = parse_afm_file("my_agent.afm.md") |
20 | | - agent = Agent(afm) |
21 | | - run_console_chat(agent) |
22 | | -""" |
23 | | - |
24 | | -from .agent import Agent |
25 | | -from .exceptions import ( |
26 | | - AFMError, |
27 | | - AFMParseError, |
28 | | - AFMValidationError, |
29 | | - AgentConfigError, |
30 | | - AgentError, |
31 | | - InputValidationError, |
32 | | - InterfaceNotFoundError, |
33 | | - JSONAccessError, |
34 | | - MCPAuthenticationError, |
35 | | - MCPConnectionError, |
36 | | - MCPError, |
37 | | - MCPToolError, |
38 | | - OutputValidationError, |
39 | | - ProviderError, |
40 | | - TemplateCompilationError, |
41 | | - TemplateError, |
42 | | - TemplateEvaluationError, |
43 | | - VariableResolutionError, |
44 | | -) |
45 | | -from .interfaces import ( |
46 | | - WebSubSubscriber, |
47 | | - ChatApp, |
48 | | - async_run_console_chat, |
49 | | - create_webchat_app, |
50 | | - create_webhook_app, |
51 | | - get_console_interface, |
52 | | - get_http_path, |
53 | | - get_interface_by_type, |
54 | | - get_interfaces, |
55 | | - get_primary_interface, |
56 | | - get_webchat_interface, |
57 | | - get_webhook_interface, |
58 | | - has_interface_type, |
59 | | - run_console_chat, |
60 | | - run_webchat_server, |
61 | | - run_webhook_server, |
62 | | - verify_webhook_signature, |
63 | | -) |
64 | | -from .models import ( |
65 | | - AFMRecord, |
66 | | - AgentMetadata, |
67 | | - ClientAuthentication, |
68 | | - CompiledTemplate, |
69 | | - ConsoleChatInterface, |
70 | | - Exposure, |
71 | | - HeaderVariable, |
72 | | - HTTPExposure, |
73 | | - Interface, |
74 | | - InterfaceType, |
75 | | - JSONSchema, |
76 | | - LiteralSegment, |
77 | | - MCPServer, |
78 | | - Model, |
79 | | - PayloadVariable, |
80 | | - Provider, |
81 | | - Signature, |
82 | | - Subscription, |
83 | | - TemplateSegment, |
84 | | - ToolFilter, |
85 | | - Tools, |
86 | | - Transport, |
87 | | - TransportType, |
88 | | - WebChatInterface, |
89 | | - WebhookInterface, |
90 | | - get_filtered_tools, |
91 | | -) |
92 | | -from .parser import parse_afm, parse_afm_file, validate_and_extract_interfaces |
93 | | -from .providers import ( |
94 | | - create_model_provider, |
95 | | - get_supported_providers, |
96 | | -) |
97 | | -from .schema_validator import ( |
98 | | - build_output_schema_instruction, |
99 | | - coerce_output_to_schema, |
100 | | - extract_json_from_response, |
101 | | - json_schema_to_dict, |
102 | | - validate_input, |
103 | | - validate_output, |
104 | | -) |
105 | | -from .templates import access_json_field, compile_template, evaluate_template |
106 | | -from .tools import ( |
107 | | - MCPClient, |
108 | | - MCPManager, |
109 | | - filter_tools, |
110 | | -) |
111 | | -from .variables import ( |
112 | | - contains_http_variable, |
113 | | - resolve_variables, |
114 | | - validate_http_variables, |
115 | | -) |
116 | | -from .cli import create_unified_app, main |
117 | | - |
118 | 4 | __version__ = "0.1.0" |
119 | | - |
120 | | -__all__ = [ |
121 | | - # Version |
122 | | - "__version__", |
123 | | - # Parser Functions |
124 | | - "parse_afm", |
125 | | - "parse_afm_file", |
126 | | - "validate_and_extract_interfaces", |
127 | | - # Variables |
128 | | - "resolve_variables", |
129 | | - "contains_http_variable", |
130 | | - "validate_http_variables", |
131 | | - # Templates |
132 | | - "compile_template", |
133 | | - "evaluate_template", |
134 | | - "access_json_field", |
135 | | - # Models |
136 | | - "AFMRecord", |
137 | | - "AgentMetadata", |
138 | | - "Provider", |
139 | | - "Model", |
140 | | - "ClientAuthentication", |
141 | | - "Transport", |
142 | | - "TransportType", |
143 | | - "ToolFilter", |
144 | | - "MCPServer", |
145 | | - "Tools", |
146 | | - "JSONSchema", |
147 | | - "Signature", |
148 | | - "HTTPExposure", |
149 | | - "Exposure", |
150 | | - "Subscription", |
151 | | - "InterfaceType", |
152 | | - "ConsoleChatInterface", |
153 | | - "WebChatInterface", |
154 | | - "WebhookInterface", |
155 | | - "Interface", |
156 | | - "CompiledTemplate", |
157 | | - "LiteralSegment", |
158 | | - "PayloadVariable", |
159 | | - "HeaderVariable", |
160 | | - "TemplateSegment", |
161 | | - "get_filtered_tools", |
162 | | - # Exceptions |
163 | | - "AFMError", |
164 | | - "AFMParseError", |
165 | | - "AFMValidationError", |
166 | | - "VariableResolutionError", |
167 | | - "TemplateError", |
168 | | - "TemplateCompilationError", |
169 | | - "TemplateEvaluationError", |
170 | | - "JSONAccessError", |
171 | | - # Agent Class |
172 | | - "Agent", |
173 | | - # Provider Factory |
174 | | - "create_model_provider", |
175 | | - "get_supported_providers", |
176 | | - # Schema Validation |
177 | | - "validate_input", |
178 | | - "validate_output", |
179 | | - "coerce_output_to_schema", |
180 | | - "extract_json_from_response", |
181 | | - "json_schema_to_dict", |
182 | | - "build_output_schema_instruction", |
183 | | - "AgentError", |
184 | | - "AgentConfigError", |
185 | | - "ProviderError", |
186 | | - "InputValidationError", |
187 | | - "OutputValidationError", |
188 | | - "InterfaceNotFoundError", |
189 | | - # MCP Exceptions |
190 | | - "MCPError", |
191 | | - "MCPConnectionError", |
192 | | - "MCPToolError", |
193 | | - "MCPAuthenticationError", |
194 | | - # MCP Classes |
195 | | - "MCPClient", |
196 | | - "MCPManager", |
197 | | - "filter_tools", |
198 | | - # Interface Functions |
199 | | - "get_interfaces", |
200 | | - "get_interface_by_type", |
201 | | - "get_console_interface", |
202 | | - "get_webchat_interface", |
203 | | - "get_webhook_interface", |
204 | | - "get_primary_interface", |
205 | | - "has_interface_type", |
206 | | - "get_http_path", |
207 | | - "ChatApp", |
208 | | - "run_console_chat", |
209 | | - "async_run_console_chat", |
210 | | - "create_webchat_app", |
211 | | - "run_webchat_server", |
212 | | - "create_webhook_app", |
213 | | - "run_webhook_server", |
214 | | - "WebSubSubscriber", |
215 | | - "verify_webhook_signature", |
216 | | - # CLI |
217 | | - "main", |
218 | | - "create_unified_app", |
219 | | -] |
0 commit comments