diff --git a/modules/chatbot_api_apiai/src/IntentRequestApiAiProxy.php b/modules/chatbot_api_apiai/src/IntentRequestApiAiProxy.php
index c05fd1b..55cd5db 100644
--- a/modules/chatbot_api_apiai/src/IntentRequestApiAiProxy.php
+++ b/modules/chatbot_api_apiai/src/IntentRequestApiAiProxy.php
@@ -76,17 +76,24 @@ class IntentRequestApiAiProxy implements IntentRequestInterface {
    */
   public function getIntentAttribute($name, $default = NULL) {
     $value = $default;
+    $context_name = $this->getContextName($name);
     $contexts = $this->original->getResult()->getContexts();
 
-    // Extract context.
-    if (isset($contexts[$this->getContextName($name)]) && $contexts[$this->getContextName($name)] instanceof Context) {
-
-      // API.ai supports context parameters. Intents can get/set parameters
-      // by separating the context name and the parameter name with a period
-      // i.e. context_name.parameter_name .
-      $params = $contexts[$this->getContextName($name)]->getParameters();
-
-      $value = isset($params[$this->getParameterName($name)]) ? $params[$this->getParameterName($name)] : $default;
+    // Loop contexts to find a match.
+    foreach ($contexts as $context) {
+      // Extract context.
+      if ($context instanceof Context && $context->getName() === $context_name) {
+
+        // API.ai supports context parameters. Intents can get/set parameters
+        // by separating the context name and the parameter name with a period
+        // i.e. context_name.parameter_name .
+        $params = $context->getParameters();
+
+        // Early return if parameter exists.
+        if (isset($params[$this->getParameterName($name)])) {
+          return $params[$this->getParameterName($name)];
+        }
+      }
     }
 
     return $value;
diff --git a/modules/chatbot_api_apiai/src/IntentResponseApiAiProxy.php b/modules/chatbot_api_apiai/src/IntentResponseApiAiProxy.php
index 66a8c8a..395c504 100644
--- a/modules/chatbot_api_apiai/src/IntentResponseApiAiProxy.php
+++ b/modules/chatbot_api_apiai/src/IntentResponseApiAiProxy.php
@@ -51,6 +51,22 @@ class IntentResponseApiAiProxy implements IntentResponseInterface {
    * {@inheritdoc}
    */
   public function addIntentAttribute($name, $value) {
+
+    // Lookup for existing context.
+    $contexts = $this->original->get('contextOut', []);
+    /** @var \ApiAi\Model\Context $context */
+    foreach ($contexts as $context) {
+      if ($context->getName() === $this->getContextName($name)) {
+        // Original library doesn't allow parameters settings. Let's work
+        // this around.
+        $params = $context->getParameters();
+        $params[$this->getParameterName($name)] = $value;
+        $context->add('parameters', $params);
+        return;
+      }
+    }
+
+    // No context with this name has been found. Create a new one.
     $data = [
       'name' => $this->getContextName($name),
       'parameters' => [
diff --git a/modules/chatbot_api_apiai/tests/src/Unit/IntentAttributeSetGetTest.php b/modules/chatbot_api_apiai/tests/src/Unit/IntentAttributeSetGetTest.php
new file mode 100644
index 0000000..6097d8d
--- /dev/null
+++ b/modules/chatbot_api_apiai/tests/src/Unit/IntentAttributeSetGetTest.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Drupal\Tests\chatbot_api_apiai\Unit;
+
+use Drupal\api_ai_webhook\ApiAi\Model\Webhook\Request;
+use Drupal\api_ai_webhook\ApiAi\Model\Webhook\Response;
+use Drupal\chatbot_api_apiai\IntentRequestApiAiProxy;
+use Drupal\chatbot_api_apiai\IntentResponseApiAiProxy;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests set/get intent attributes for Api.AI proxy classes.
+ *
+ * @group chatbot_api
+ */
+class IntentAttributeSetGetTest extends UnitTestCase {
+
+  /**
+   * Tests getIntentAttribute() method.
+   */
+  public function testGetIntentAttribute() {
+    $request_data = [
+      'timestamp' => '2017-02-09T16:06:01.908Z',
+      'result' => [
+        'contexts' => [
+          [
+            'name' => 'weather',
+            'lifespan' => 2,
+            'parameters' => [
+              'city' => 'Rome',
+              'day' => 'Monday',
+            ],
+          ],
+          [
+            'name' => 'persona',
+            'lifespan' => 2,
+            'parameters' => [
+              'name' => 'Marie',
+              'gender' => 'female',
+            ],
+          ],
+        ],
+      ],
+    ];
+    $original_request = new Request($request_data);
+    $request = new IntentRequestApiAiProxy($original_request);
+
+    $this->assertEquals('Rome', $request->getIntentAttribute('weather.city'));
+    $this->assertEquals('Monday', $request->getIntentAttribute('weather.day'));
+    $this->assertEquals('Marie', $request->getIntentAttribute('persona.name'));
+    $this->assertEquals('female', $request->getIntentAttribute('persona.gender'));
+  }
+
+  /**
+   * Tests setIntentAttribute() method.
+   */
+  public function testSetIntentAttribute() {
+
+    $original_response = new Response();
+    $response = new IntentResponseApiAiProxy($original_response);
+
+    // Set some contexts.
+    $response->addIntentAttribute('weather.city', 'Rome');
+    $response->addIntentAttribute('weather.day', 'Monday');
+    $response->addIntentAttribute('persona.name', 'Marie');
+    $response->addIntentAttribute('persona.gender', 'female');
+    $likes = ['sea', 'food', 'drupal'];
+    $response->addIntentAttribute('persona.likes', $likes);
+
+    // Assert setter works.
+    $data = $response->jsonSerialize();
+    $this->assertArrayHasKey('contextOut', $data);
+    $this->assertEquals($data['contextOut'][0]->getName(), 'weather');
+    $this->assertEquals($data['contextOut'][0]->getParameters()['city'], 'Rome');
+    $this->assertEquals($data['contextOut'][0]->getParameters()['day'], 'Monday');
+    $this->assertEquals($data['contextOut'][1]->getName(), 'persona');
+    $this->assertEquals($data['contextOut'][1]->getParameters()['name'], 'Marie');
+    $this->assertEquals($data['contextOut'][1]->getParameters()['gender'], 'female');
+    $this->assertEquals($data['contextOut'][1]->getParameters()['likes'], $likes);
+
+    // Change some parameters. Change the value type too, to make sure
+    // overriding the value type is allowed.
+    $response->addIntentAttribute('weather.day', ['Monday', 'Thursday']);
+    $response->addIntentAttribute('persona.likes', 'all the small things');
+
+    // Assert setter works with changing existing values and their types.
+    $data = $response->jsonSerialize();
+    $this->assertEquals($data['contextOut'][0]->getParameters()['day'], ['Monday', 'Thursday']);
+    $this->assertEquals($data['contextOut'][1]->getParameters()['likes'], 'all the small things');
+
+    // Also make sure previous parameters are unaltered.
+    $this->assertEquals($data['contextOut'][0]->getParameters()['city'], 'Rome');
+    $this->assertEquals($data['contextOut'][1]->getParameters()['gender'], 'female');
+  }
+
+}
